- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Unfortunately, SimpleDateFormat isn't threadsafe either, so it can't be cached in a threaded context either; this is because it stores the calendar passed for formatting (and possibly the string for parsing) and/or uses a member variable for output. The standard recommendation is to create a new instance every time you need one, otherwise you get strange output. This is one of the reasons I prefer JodaTime (and am looking forward to the new date/time API)
Admin
There's no clarification because you're the first person I've seen who's ever thought that the method might be returning a singleton instance. The Java date APIs are crap (if thankfully improving in Java 8), but they're not so bad that they only allow you to use a single date in the system...
Admin
Java 8's new date/time API is strongly inspired by Joda (not identical, but very similar), so perhaps that will give you what you want.
Admin
It's just you. A Java 'int' is 32-bit, but a 'long' is (and always has been) a 64-bit value.
Admin
You could pool them, the safety guarantee is only around concurrent access ... if you make the operations atomic, you will NEVER get a mangled date ...
However +1 to the new date/time API and I also agree Joda time is far superior.
Admin
Admin
Nobody has noticed this yet?
The resulting date format is not yyyyMMddhhmmss
It is yyyyMMddhhmmssSSS
where SSS is the number of milliseconds (i.e. currtime % 1000L)
Also, there is not an off-by-1 error, because Calendar.MONTH returns a month that is zero-based. January is month 0, so adding 1 is correct.
Admin
You mean: yyyyMMddHHmmssSSS
And why not include the timezone: yyyyMMddHHmmssSSSZ
Admin
Why not include the timezone? Because the timezone can't be expressed in a number from 0 to 9, of course.
Admin
Admin
Admin
Parents can be so difficult...
Admin
Seems that DateTimes confuse the hell out of people. Here's something I found in one of the programs at my workplace:
Yes. It is really converting the Day of the date to int to check, if date1 was three/two/one days prior to date2. And yes again, it really does the same thing for the months again.
Admin