How can I get the count of milliseconds since midnight for the current?

Lemonio picture Lemonio · Aug 2, 2012 · Viewed 391.9k times · Source

Note, I do NOT want millis from epoch. I want the number of milliseconds currently on the clock.

So for example, I have this bit of code.

Date date2 = new Date(); 
Long time2 = (long) (((((date2.getHours() * 60) + date2.getMinutes())* 60 ) + date2.getSeconds()) * 1000);

Is there a way to get milliseconds with date? Is there another way to do this?

Note: System.currentTimeMillis() gives me millis from epoch which is not what I'm looking for.

Answer

Peter Lawrey picture Peter Lawrey · Aug 2, 2012

Do you mean?

long millis = System.currentTimeMillis() % 1000;

BTW Windows doesn't allow timetravel to 1969

C:\> date
Enter the new date: (dd-mm-yy) 2/8/1969
The system cannot accept the date entered.