Created
April 19, 2021 09:26
-
-
Save geordee/f4798d7653e658f1652ad6020757360a to your computer and use it in GitHub Desktop.
Timestamp Conversion and Comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.format.DateTimeFormatter; | |
import java.time.temporal.ChronoUnit; | |
import java.time.OffsetDateTime; | |
import java.time.ZonedDateTime; | |
import java.util.Date; | |
class Main { | |
public static void main(String args[]) { | |
String documentDateTime = "2022-02-02T12:00:00+04:00"; | |
String createDateTime = "2022-02-02T08:15:00.000Z"; | |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss Z"); | |
ZonedDateTime createDateTimeZ = ZonedDateTime.parse(createDateTime) ; | |
System.out.println(createDateTimeZ.format(formatter)); | |
System.out.println(createDateTimeZ.format(DateTimeFormatter.ISO_ZONED_DATE_TIME)); | |
ZonedDateTime documentDateTimeZ = ZonedDateTime.parse(documentDateTime); | |
System.out.println(documentDateTimeZ.format(formatter)); | |
System.out.println(documentDateTimeZ.format(DateTimeFormatter.ISO_ZONED_DATE_TIME)); | |
long differenceInMinutes = ChronoUnit.MINUTES.between(documentDateTimeZ, createDateTimeZ); | |
System.out.println(differenceInMinutes); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment