I have a date string looking like this:
String time1 = "2018-08-28T10:23:25.617Z";
I want to get the difference between this date to the current date in utc time. What is the easiest way to do it? thanks.
I have a date string looking like this:
String time1 = "2018-08-28T10:23:25.617Z";
I want to get the difference between this date to the current date in utc time. What is the easiest way to do it? thanks.
You can use java.time.Instant
and java.time.Duration
:
Instant instant = Instant.parse("2018-08-28T10:23:25.617Z"); // start time in UTC
Instant now = Instant.now(); // end time in UTC
Duration duration = Duration.between(instant, now); // the Duration
System.out.println(duration.toSeconds()); // duration in seconds