1. 程式人生 > >java8 日期時間解析與轉換

java8 日期時間解析與轉換


Instant now = Instant.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
String formated = formatter.format(now);
TemporalAccessor temporalAccessor = formatter.parse(formated);
Instant instantNow = Instant.from(temporalAccessor);

TemporalAccessor set = formatter.parse("2018-12-26 10:55:24");
Instant instantSet = Instant.from(set);
System.out.println(instantNow.isAfter(instantSet));