如何从日历中获取 UTC 时间戳?
2022-09-04 05:58:00
在Java中,当我使用时,我得到当前时区的对象。但通常以 UTC 时间存储,而不是以本地时间存储。那么如何从日历实例获取 UTC 时间呢?Calendar.getInstance();
Calendar
java.sql.Timestamp
DateFormat df = DateFormat.getTimeInstance();
Calendar cal = Calendar.getInstance();
Timestamp time = new Timestamp(cal.getTimeInMillis());
// Prints local time
System.out.println(df.format(new Date(time.getTime())));
// Printe local time, but I want UTT Time
System.out.println("timestamp: " + time);