The moose likes Beginning Java and the fly likes date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "date format" Watch "date format" New topic

date format

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
Date today = new Date();
SimpleDateFormat df = new SimpleDateFormat("MM/DD/yyyy");
System.out.println("today is " + df.format(today));

I got

today is 04/98/2008

instead of

today is 04/07/2008

what is wrong ??
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
From the SimpleDateFormat javadoc
D Day in year Number
d Day in month Number

Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

then it should be like that.

These following pattern letters are defined in Java Docs (characters from 'A' to 'Z' and from 'a' to 'z' are reserved to do specific presentation).

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
I agree. Here's the link:
subject: date format
jQuery in Action, 3rd edition