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

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


Do you mean?

long millis = System.currentTimeMillis() % 1000;

BTW Windows doesn't allow timetravel to 1969

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


Use Calendar

Calendar.getInstance().get(Calendar.MILLISECOND);

or

Calendar c=Calendar.getInstance();c.setTime(new Date()); /* whatever*///c.setTimeZone(...); if necessaryc.get(Calendar.MILLISECOND);

In practise though I think it will nearly always equal System.currentTimeMillis()%1000; unless someone has leap-milliseconds or some calendar is defined with an epoch not on a second-boundary.


Calendar.getInstance().get(Calendar.MILLISECOND);