Skip to content
Advertisement

Tag: epoch

converting epoch to ZonedDateTime in Java

How to convert epoch like 1413225446.92000 to ZonedDateTime in java? The code given expects long value hence this will throw NumberFormatException for the value given above. Answer java.time can directly parse your string Edit: If your millisecond value is always non-negative, the following DateTimeFormatter can parse it. Now parsing into a ZonedDateTime is just one method call: Output is: 2014-10-13T11:37:26.920-07:00[America/Los_Angeles]

Epoch time confusion, clarification needed

Given: 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? UPDATE: I continue to second guess myself due to For the same time period i

How do you create a proper Epoch calendar object in Java?

I want to create a calendar object that is the epoch date. What’s the ‘correct’ (if any) way to do it? Answer The ‘setTimeInMillis()’ method would work fine and be easily understood by others. It might also be clearer if you passed it 0 instead of 1. The first method has more line noise and just adds more chances that

Advertisement