// 当前时间及时间差
// java11
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss").withZone(ZoneId.systemDefault());
Instant t1 = Instant.now();
System.out.println(dtf.format(t1));
Instant t2 = Instant.now();
System.out.println(dtf.format(t2));
System.out.println(t2.toEpochMilli() - t1.toEpochMilli());
// java8
// 获取当前时间
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String time = dtf.format(LocalDateTime.now());
System.out.println(time);
// 根据指定时间获取 距离1970年1月1日的 秒数// java8
LocalDateTime ldt = LocalDateTime.of(2020, 9, 20, 21, 57, 0);
long l1 = ldt.toEpochSecond(ZoneOffset.ofHours(8));
System.out.println(l1);
// 根据毫秒数构造日期对象
long l = 1600610251818;
Instant i = Instant.ofEpochMilli(l);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(ZoneId.systemDefault());
System.out.println(dtf.format(i));
// java7
Date date = new Date();
Long time = date.getTime();
System.out.println(time);
Date d = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(d));