我想以毫秒为单位将日期转换为日期,但转换不正确。
public static void main(String[] args) {
LocalDate today = LocalDateTime.now().toLocalDate();
System.out.println("Today: ----------" + today);
long todayLong = today.atStartOfDay(ZoneId.systemDefault()).toEpochSecond();
System.out.println("todayLong: ---------- " + todayLong);
LocalDate todayBack = Instant.ofEpochMilli(todayLong).atZone(ZoneId.systemDefault()).toLocalDate();
System.out.println("todayBack: ---------- "+todayBack);
}
这是输出:
今天:---------2017-06-27
今天长: ---------- 1498507200
今天返回: ---------- 1970-01-18