This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes SimpleDateFormat returns inconsistent date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "SimpleDateFormat returns inconsistent date" Watch "SimpleDateFormat returns inconsistent date" New topic
Author

SimpleDateFormat returns inconsistent date

Sam Kumar
Ranch Hand

Joined: Nov 30, 2001
Posts: 38
Hi,
I am seeing very strange problem with SimpleDateFormat, sometime I am seeing
four digit month instead of two between clone. For example first clone (JVM) will
return two digit month "01" and another clone (same code) return four digit
month "0001".
Here is the code snippet:
private static String customTimestamp;
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss z");
.....
if (customTimestamp == null)
customTimestamp = formatter.format(new java.util.Date());
We are using JDK 1.3.1, WAS 4 AE, AIX
Any thoughts why i am getting different month length.
Thanks.
SK
Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
hi sushil,
I tried ur code on my machine.
But im gettin consistant results.(4 digit year)
Also what do u mean by JVM clone???
I have run the code on my Win Nt machine on JDK 1.4.
Thanks,
Chinmay


The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Sam Kumar
Ranch Hand

Joined: Nov 30, 2001
Posts: 38
Hi Chinmay:
Thanks for your reply.
We are using WebSphere Application Server and for scalability reasons we created cloned AppServer i.e. multiple JVMs are running the same web application.
I am seeing 4 digit month instead of two. For example: For Jan, first JVM shows "01" and 2nd JVM may show "0001". All other informaiton is correct based on format specified in SimpleDateFormat.
Also this problem is not consistent, I saw only twice.
I am using JDK 1.3.1 running on AIX (unix).
Thanks.
Sushil
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SimpleDateFormat returns inconsistent date
 
Similar Threads
internationalization - date format
SimpleDateFormat returns 4digit month
customized pop-up dialog
JFormattedTextField and DateFormat problems
confusing output of a date