Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateFormat with no milliseconds

Tags:

java

This is probably a simple question but I can't seem to find the solution.

I have a time string that is 8 digits long (epoch seconds), when I try to format this using the Java DateFormat, it always assumes that my time contains milliseconds as well, so 16315118 converts to: 4:31:55.118 instead of the correct time of 19:58:38.

I do not want to edit the string to add in the milliseconds, so how can I do this?

I also do not want to multiply by 1000 since I am using this for formatting of other times that includes milliseconds.

like image 275
z - Avatar asked Nov 24 '25 06:11

z -


1 Answers

I also do not want to multiply by 1000 since I am using this for formatting of other times that includes milliseconds.

You're out of luck. You can't use the same DateFormat to format two different time values. Either use two different formatters or (more correctly) convert your time values.

Your time values should be in milliseconds because that is what the API expects. Anything else is a hack

like image 57
Kevin Avatar answered Nov 26 '25 19:11

Kevin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!