Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get number of milliseconds from start of day [closed]

For example, if it's 1 p.m (13:00) and I need to get the number 46800000 (13 hours from beginning o day) in milliseconds. Could anyone please help?

like image 223
Toan Le Avatar asked Dec 01 '14 18:12

Toan Le


1 Answers

You can use a Calendar to calculate it. You set the time to the hour 0 and calculate the difference:

Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
long millis = (System.currentTimeMillis() - c.getTimeInMillis());
like image 93
Marcos Lima Avatar answered Nov 15 '22 23:11

Marcos Lima