File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 1323

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
It's not a secret anymore!