File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 2627
    
    9

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 OCPBCD5
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2627
    
    9

Nevermind I figured it out. The format I should have used was "yyyy/MM/dd" instead of "yyyy/mm/dd"
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: java.text.SimpleDateFormat