need help on SimpleDateFormat

Posted on 2007-10-17
Last Modified: 2008-01-09
I seem to need help on *every* class I use! I am trying to simply format a date using SimpleDateFormat, which is proving to be anything but simple! In my jsp program I get:

An error occurred at line: 138 in the jsp file: /pensionDROP.jsp
The method format(Date, StringBuffer, FieldPosition) in the type SimpleDateFormat is not applicable for the arguments (Date, String, int)
131:        SimpleDateFormat MMddyyyy = new SimpleDateFormat("MM/dd/YYYY");
132:       StringBuffer dummy = new StringBuffer();
135:           dummy.delete(0,dummy.length());
138:   <td><%= MMddyyyy.format(rs.getDate("payDate"),dummy,0)

I am assuming this is blowing up because my '0' in the format method is not a FieldPosition. First of all, I have no idea what a 'FieldPosition' is and can't figure it out from the class definition. Secondly, this is a "Simple" date format? You have got to be kidding me! I've got to import at least 3 class definitions ... I really don't even want to use the StringBuffer because the format returns a string. Is there an easier way? If not, can someone help me sort throught this and get my date formatted?
Question by:jmarkfoley
    LVL 24

    Accepted Solution

    <td><%= MMddyyyy.format(rs.getDate("payDate"),dummy,new FieldPosition(0))

    LVL 11

    Expert Comment

    Just use the format method that accepts the date, don't pass in a StringBuffer or fieldPosition.  This is specified in the Format class, not SimpleDateFormat.
    LVL 26

    Expert Comment

    jmarkfoley - it isn't just you on this one.  For some reason, date handling is a pain in Java.  Almost everything else is well done, so we all just learn to live with this one.

    This page has a lot of info on formatting dates in Java:
    LVL 92

    Expert Comment

    you really should avoid putting java code in your jsp and instead use tags
    jstl provides tags for doing date formatting

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    VB Script 3 60
    withoutTen challenge 14 69
    Logs to delete in Windows VCenter server ? 11 89
    Running Jira on Raspberry PI 2? 3 44
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now