Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time in seconds to custom string format

Tags:

java

date

time

I'm trying to get a double value with seconds to convert to a custom time format. I've tried SimpleDate Format but that doesn't work...

I have a double value in this format: 407.33386569554585 (representing 407 seconds and 333 milliseconds ...).

I need that in this format: HH/MM/SS.MS

How would i do that?

Thanks in advance!

like image 951
Diesal11 Avatar asked Nov 13 '11 23:11

Diesal11


People also ask

What is TT time format?

Terrestrial Time (TT) is a modern astronomical time standard defined by the International Astronomical Union, primarily for time-measurements of astronomical observations made from the surface of Earth.

How do you add time to a string?

var dateValue = new Date("2021-01-12 10:10:20"); Use new Date() along with setHours() and getHours() to add time.


1 Answers

Multiply by 1,000 then cast to a long and construct a Date with it.

Date date = new Date((long)(dubTime*1000));

From here, you can use a SimpleDateFormat to make the string you'd like.

String formattedDate = new SimpleDateFormat("HH/mm/ss.SSS").format(date);
like image 164
Tim Bender Avatar answered Oct 06 '22 16:10

Tim Bender