Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 917
maas Avatar asked Dec 06 '22 19:12

maas


1 Answers

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();
c.setTime(from_time);
long daySeconds = (c.get(Calendar.SECONDS) +
                   c.get(Calendar.MINUTES) * 60 +
                   c.get(Calendar.HOURS) * 3600);
like image 121
phihag Avatar answered Dec 10 '22 11:12

phihag