*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "java.text.SimpleDateFormat " Watch "java.text.SimpleDateFormat " New topic
Author

java.text.SimpleDateFormat

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2247
    
    7

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 JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2247
    
    7

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: http://aspose.com/file-tools
 
subject: java.text.SimpleDateFormat
 
Similar Threads
converting string datetime object to date object.
Behaviour of parse() method in SimpleDateFormat
why what i search is not what i want?
Date format
Date Confusion