如何将String
转换为Instant
?
我得到
线程“ main”中的异常java.lang.IllegalArgumentException:太多模式字母:s
public class Demo {
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
.withZone(ZoneId.systemDefault());
Instant instant = Instant.now();
String output = formatter.format( instant );
System.out.println(output);
// Convert String to Instant
String string = "2018-07-17T09:59:51.312Z";
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("YYYY-MM-DD'T'hh:mm:ss.sssZ", Locale.UK);
LocalDateTime date = LocalDateTime.parse(string, formatter1);
System.out.println(date.toInstant(ZoneOffset.UTC));
}
}