maas maas - 7 months ago 32
Java Question

How to convert getTime to seconds?

Can you please help in matter:

I have defined a variable which is:

Time from_time = rs.getTime("nfrm_time");

and it will read the values 7:15:00

How to convert this type to seconds?


Call getTime to get the number of milliseconds since January 1, 1970. Divide by 1000 to get it in seconds:

long unixTime = from_time.getTime() / 1000;

To get the number of seconds since 00:00 of the current day, use the

Calendar c = Calendar();
long daySeconds = (c.get(Calendar.SECONDS) +
                   c.get(Calendar.MINUTES) * 60 +
                   c.get(Calendar.HOURS) * 3600);