Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


need help on SimpleDateFormat

Posted on 2007-10-17
Medium Priority
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

sciuriware earned 2000 total points
ID: 20094839
<td><%= MMddyyyy.format(rs.getDate("payDate"),dummy,new FieldPosition(0))

LVL 11

Expert Comment

ID: 20094845
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 27

Expert Comment

ID: 20095627
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

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


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

581 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