localdatetime实现时间戳(相互转换)

xiaoxiao2021-02-28  47

Unix时间戳(Unix timestamp),或称Unix时间(Unix time)、POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00分00秒起至现在的总秒数。

java实现获得时间戳:

LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();

时间戳转换成LocalDateTime

Long timestamp = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); LocalDateTime time2 =LocalDateTime.ofEpochSecond(timestamp/1000,0,ZoneOffset.ofHours(8));
转载请注明原文地址: https://www.6miu.com/read-2622661.html

最新回复(0)