Skip to content

Instantly share code, notes, and snippets.

@spotlesscoder
Created March 21, 2019 22:25
Show Gist options
  • Save spotlesscoder/740dd67ec4057e04499f491243aef002 to your computer and use it in GitHub Desktop.
Save spotlesscoder/740dd67ec4057e04499f491243aef002 to your computer and use it in GitHub Desktop.
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