File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes java.text.SimpleDateFormat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "java.text.SimpleDateFormat " Watch "java.text.SimpleDateFormat " New topic


K. Tsang

Joined: Sep 13, 2007
Posts: 1966

Hi all, I'm doing UB assignment and in my book GUI I have a set of date combo boxes to select the year, month, day.

I use a Room object to pass the values to my services layer where the update is done. In the services layer, I use the java.text.SimpleDateFormat("yyyy/mm/dd") constructor to get my date from java.util.Date (from Room) to a string "yyyy/mm/dd" for the data file.

Now guess what? Suppose I select Jan 13 2010 in my combo boxes, the SimpleDateFormat outputs "2010/18/13" yet my GUI displays as Jan 13 2010 for that record. Then I restart my app that same record become Jun 13 2011 - that's like 18 months off.

Any one use this class for their assignment? Before I use SimpleDateFormat I physically did convert the java.util.Date to a string using its toString method and split that up and get the appropriate array index.

K. Tsang

Joined: Sep 13, 2007
Posts: 1966

Nevermind I figured it out. The format I should have used was "yyyy/MM/dd" instead of "yyyy/mm/dd"
I agree. Here's the link:
subject: java.text.SimpleDateFormat
Similar Threads
why what i search is not what i want?
Date Confusion
Date format
Behaviour of parse() method in SimpleDateFormat
converting string datetime object to date object.