Created
March 21, 2019 22:25
-
-
Save spotlesscoder/740dd67ec4057e04499f491243aef002 to your computer and use it in GitHub Desktop.
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.LocalDateTime; | |
import java.time.format.DateTimeFormatter; | |
import java.time.format.DateTimeFormatterBuilder; | |
public class Main { | |
public static void main(String[] args) { | |
String dateStr1 = "2019-01-30T12:04:12.734Z"; | |
String dateStr2 = "2019-01-30T12:04:12.21Z"; | |
DateTimeFormatter formatter = new DateTimeFormatterBuilder() | |
.append(DateTimeFormatter.ISO_LOCAL_DATE) | |
.appendLiteral('T') | |
.append(DateTimeFormatter.ISO_LOCAL_TIME) | |
.appendLiteral('Z') | |
.toFormatter(); | |
String dateTimeString = "2018-04-18T15:27:10.77Z"; | |
LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, formatter); | |
System.out.println(dateTime); | |
dateTime = LocalDateTime.parse(dateStr1, formatter); | |
System.out.println(dateTime); | |
dateTime = LocalDateTime.parse(dateStr2, formatter); | |
System.out.println(dateTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment