• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SimpleDateformat not working and added minutes to output

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

input:2016-02-26 21:00:52.823166
Output:2016-02-26 09:14:35.000166 PM
Expected :2016-02-26 09:00:52.823166 PM
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "SSS" with the SimpleDateFormat is in milliseconds. So, the normalized range is from 0 to 999.

And 823166 milliseconds works out to about 13 minutes, and 43 seconds... which of course, are added, once the number of milliseconds are normalized.

Henry

PS.... welcome to the ranch.
 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you need a resolution down to nanoseconds use the formatters in the Java.time package.
Note: The java.time package has only been available since Java 8.
 
Kamesh Jiya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:The "SSS" with the SimpleDateFormat is in milliseconds. So, the normalized range is from 0 to 999.

And 823166 milliseconds works out to about 13 minutes, and 43 seconds... which of course, are added, once the number of milliseconds are normalized.

Henry

PS.... welcome to the ranch.



Thanks Henry,  any idea..how can I expect similar expected output. This value used as input to my SQL if minutes cahnges.. output also varies.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kamesh Jiya wrote:
Thanks Henry,  any idea..how can I expect similar expected output. This value used as input to my SQL if minutes cahnges.. output also varies.



Well, you can use the time package mentioned by Tony. Or even a third party option. These are probably your easiest options.

If those options are not possible, you can either write code to parse it yourself -- which will likely be your hardest option. Or since it is just the fraction of sections portion, extract it from the string, use SimpleDateFormat without it, and reinsert it back later. Of course, that assumes that the fraction is normalized.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic