Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting date in java

Status
Not open for further replies.

RegK

Programmer
Jan 24, 2003
2
GB

I want to be able to change the format of the date returned from an access database 1999-09-01 00:00:00 to standard format eg. 24/01/03

here is the code i used

String dbdate = rsCV.getString("thirdlevelDateFrom");

//Date today = new Date();
DateFormat formatter;
formatter = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);

Date thedate = formatter.parse(dbdate);
out.println(formatter.format(thedate)) ;

This gives me the following error

javax.servlet.ServletException: Unparseable date: "1999-09-01 00:00:00"

any ideas
 
You're pretty close. Just use

formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

instead of
formatter = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);

because you have your own format, not necessarily precisely the US standard.

Hope this helps,
Joseph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top