java 1.8 中 关于LocalDateTime 的与long 的转换,在1.8 localdateTime 中对于时区设置是敏感的,这个须要留意 public static void main(String[] args) { Period sixMonths = Period.ofMonths(1); LocalDate date = LocalDate.now(); LocalDate future = date.minus(sixMonths); System.out.println(future); LocalDateTime d = LocalDateTime.ofInstant(Instant.ofEpochMilli(System.currentTimeMillis()), ZoneId.systemDefault()); System.out.println(d.minus(sixMonths).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); ZoneId zoneId = ZoneId.systemDefault(); // or: ZoneId.of("Europe/Oslo"); long epoch = date.atStartOfDay(zoneId).toEpochSecond(); System.out.println(epoch); System.out.println(new Date(1490585496969l)); System.out.println(ZoneId.systemDefault()); Set<String> set = new HashSet<>(); if (set.isEmpty()){ System.out.println("true"); } }