Skip to content
Advertisement

Epoch time confusion, clarification needed

Given:

JavaScript

As i understand it, the result comes back with time since the epoch, in milliseconds

The current time as UTC milliseconds from the epoch.

Given that my test always sets the objects the same, why are results coming up different as time goes by?

JavaScript

UPDATE:

I continue to second guess myself due to enter image description here

For the same time period i get

JavaScript

Advertisement

Answer

I think you should use clear(). If you do that it will return you the exact number of miliseconds each time.

JavaScript

From Java doc

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined. This means that isSet() will return false for all the calendar fields, and the date and time calculations will treat the fields as if they had never been set. A Calendar implementation class may use its specific default field values for date/time calculations. For example, GregorianCalendar uses 1970 if the YEAR field value is undefined.

A Sample program

JavaScript

Output:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement