简体   繁体   中英

Java microseconds formatter

In database, i have timestamp values like

2005-JAN-13 07:15:31.22222

I want to format above value in java to

2005-05-13 07:15:31.22222

fot this i used formetter: yyyy-MM-dd HH:mm:ss:SSSSS but when i use above formetter , it is giving value as follows:

2005-05-13 07:15:31:00222

instead of 2005-05-13 07:15:31.22222

can any one pls suggest java formater to get the value as follows:

2005-05-13 07:15:31.22222

AFAIK Java dates are up to millisecond precision, thus you can't format microseconds. The best you can get would be 2005-05-13 07:15:31.22200 (note that the trailing zeros would have to be appended by you, since the millisecond part would be 222 and thus would be formatted as 00222 when having the format string like SSSSS ).

the standard date formats do not support microsecond precision. What you are getting is the milliseconds formatted into a 5 character wide millisecond field.

You would need to do your own manual formatting on microseconds and append it to the string yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM