• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

SimpleDateFormat returns 4digit month

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you displaying the erroneous results? Exactly what does such a result look like?
 
Sam Kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic