I want to migrate this code from Joda-Time to its replacement, java.time (JSR 310).
Specifically I want to use ZonedDateTime.
Old code:
DateTime startTime = new DateTime();
DateTime stopTime = new DateTime();
durationMilli = Math.max(1, (stopTime.getMillis() - startTime.getMillis()));
to
ZonedDateTime startTime = ZonedDateTime.now();
ZonedDateTime stopTime = ZonedDateTime.now();
durationMilli = Math.max(1, (stopTime.getMillis() - startTime.getMillis()));
I have the following questions.
How I can set ZonedDateTime.now() to empty value? As you can see stopTime should be empty.
Send issue is that method getMillis is missing. How I can get milliseconds?
I dont think there is a need to set
ZonedDateTime.now()to empty value. You can usezonedDateTime.toInstant()and theninstant.toEpochMilli()to get it in milliseconds.