aspose file tools*
The moose likes Beginning Java and the fly likes !SimpleDateFormat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "!SimpleDateFormat" Watch "!SimpleDateFormat" New topic
Author

!SimpleDateFormat

William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

This works:

But trying to set the date to something tells me I am using deprecated methods.
So I try and use GregorianCalendar but than I don't know how to get back to SimpleDateFormat or DateFormat to be able to print it out as "Month Day Year".
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

The three lines of code you have posted do not give any compile warnings and work as anticipated. Did you leave out some other code? Just for reference, this is how you get a date object from a Calendar/GregorianCalendar object:

Jamie
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

I stated that the code I posted worked.
You answered my question when you showed me how to get the 'date' object using 'getTime()', thanks.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

And I quickly notice that month 1 is February, not January. Wow that is dumb.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Originally posted by William Barnes:
And I quickly notice that month 1 is February, not January. Wow that is dumb.
yeah, I used to catch myself doing that too. So, now I exclusively use the static field Calendar.DECEMBER... etc to avoid forgetting.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It's the old array issue... create an array of month names and then use the month to get them. If the month is 1-12 then you have to subtract one. Since the months are 0-11, you don't have to subtract one. I'm sure Java does this because all the other languages do it.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: !SimpleDateFormat