• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

simpledateformat

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a date format of yyyy-MM-dd-HH.mm.ss.SSSSSS and need to convert it to yyyy-MM-dd HH:mm:ss.S

but say when i pass the date 2010-02-16-23.59.59.999000 i m getting the formated date as 2010-02-17 00:16:38.000

 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This I think is due to the different TIMEZONE. You can look at the SimpleDateFormat API to see the format for specifying the Timezone.
 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Milliseconds is always three digit. Even if "SSSSSS" is given
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I told suggested to check with TIMEZONE as there was a difference between the 2 dates (~16 minutes if I am not wrong).

Update: and it looks like a difference of 1 day
 
Sheriff
Posts: 22700
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prakash is right. You probably expect the 999000 to be read as 999, but it is read as 999000, then truncated to 0 (999000 % 1000 == 0).
 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But why is the date incrementing by 1 day.
 
Prakash Krsihnan
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you convert "999000" ms to minute it comes to 17:38 and it added to date.
It advisable to use only SSS or S. Don't use more than three S for microseconds
 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prakash Krsihnan wrote:If you convert "999000" ms to minute it comes to 17:38 and it added to date.
It advisable to use only SSS or S. Don't use more than three S for microseconds



Thank you very much
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prakash Krsihnan wrote:If you convert "999000" ms to minute it comes to 17:38 and it added to date.
It advisable to use only SSS or S. Don't use more than three S for microseconds


Oh nice catch. It struck to me as a TIMEZONE issue.
 
Rob Spoor
Sheriff
Posts: 22700
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prakash Krsihnan wrote:If you convert "999000" ms to minute it comes to 17:38 and it added to date.
It advisable to use only SSS or S. Don't use more than three S for microseconds


So I was wrong - the 999000 isn't truncated at all but added as additional milliseconds.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic