Mark
asked on
need help on SimpleDateFormat
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/YY YY");
132: StringBuffer dummy = new StringBuffer();
135: dummy.delete(0,dummy.lengt h());
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?
THX
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/YY
132: StringBuffer dummy = new StringBuffer();
135: dummy.delete(0,dummy.lengt
138: <td><%= MMddyyyy.format(rs.getDate
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?
THX
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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:
http://javatechniques.com/blog/dateformat-and-simpledateformat-examples/
This page has a lot of info on formatting dates in Java:
http://javatechniques.com/blog/dateformat-and-simpledateformat-examples/
you really should avoid putting java code in your jsp and instead use tags
jstl provides tags for doing date formatting
http://www.onjava.com/pub/a/onjava/2002/09/11/jstl2.html
jstl provides tags for doing date formatting
http://www.onjava.com/pub/a/onjava/2002/09/11/jstl2.html