LocalDateTime 转时间戳

 @Test
    public void printSS()
    {
        LocalDateTime date = LocalDateTime.of(2020,6,7,12,3,4,4);
        System.out.println(date.toInstant(ZoneOffset.of("+8")).toEpochMilli());
    }

1591502584000

获取中国时间的时间戳

public class TimeUtils {
    /**
     * @return 返回 时间戳(中国时间)
     */
    public static Instant now(){
        return Instant.now().plusMillis(TimeUnit.HOURS.toMillis(8));
    }
}
发布了175 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43923045/article/details/105200886