| Author |
SimpleDateFormat returns 4digit month
|
Sam Kumar
Ranch Hand
Joined: Nov 30, 2001
Posts: 38
|
|
Hi, I am seeing very strange problem with SimpleDateFormat. I am formatting java.util.Date into a timestamp value, here is the snippet: SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss z"); formatter.format(new java.util.Date()); I saw twice 4digit month but it is not happening every time. 0001/31/2003 12:24:56 GMT+00:00 Any thoughts! Thanks in adance. SK
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
How are you displaying the erroneous results? Exactly what does such a result look like?
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Sam Kumar
Ranch Hand
Joined: Nov 30, 2001
Posts: 38
|
|
I am storing formatted timestamp value in static String variable which is initialized in a servlet on first access. I saw following resuly twice: "0001/31/2003 12:24:56 GMT+00:00" note the month as "0001" as oppose to "01". This is not happening always. Thanks. SK
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Do you need this value to be set once only on servlet initialization? If so, make the variable into a constant with final, and initializing it in a static initializer block. This is just an idea that I would try myself (meaning it might not work) -Barry
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
 |
|
|
subject: SimpleDateFormat returns 4digit month
|
|
|