时间格式

(1)获取当前时间前两个小时的时间

LocalDateTime now = LocalDateTime.now();
LocalDateTime oneHourAgo = now.minusHours(2);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String two_hour_ago = oneHourAgo.format(formatter);

(2)前后时间计算(ms)

long l = System.currentTimeMillis();
long l2 = System.currentTimeMillis();

l2 -l ms


posted @ 2023-12-28 09:15  试着看清楚  阅读(55)  评论(0)    收藏  举报