This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 374
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: 3418
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: 374
I agree. Here's the link:
subject: date format
Similar Threads
date format
Convert String to Java Date
Time Zone problem
Converting from string to date
convert String to Date Format