时间戳是时间吗?如何在java中获取utc时间并转换为本地时间(毫秒)?

时间:2015-09-19 11:22:25

标签: java time timestamp utc

TIMESTAMP是时候吗? 如何在java中获取utc时间并转换为本地时间(毫秒)?

2 个答案:

答案 0 :(得分:0)

您可以将时间戳对象转换为本地时间:

object.toLocalDateTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());

https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html#toLocalDateTime--

答案 1 :(得分:0)

使用此

Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
System.out.println(cal.getTime());

使用SimpleDateFormatter将其转换为本地时间(毫秒)