简体   繁体   English

如何在GMT中获取java.sql.Time

[英]How to obtain java.sql.Time in GMT

I have an object java.sql.Time from which I need to obtain the time in millisecond. 我有一个对象java.sql.Time ,我需要从中获取时间(以毫秒为单位)。 I can not use getTime() function. 我不能使用getTime()函数。 I noticed that there is a deprecated function getTimeZoneOffset . 我注意到有一个不赞成使用的函数getTimeZoneOffset So, I don't want to use it. 所以,我不想使用它。 What else can I use? 我还能使用什么? I am also using JVM 7. Thanks in advance. 我也在使用JVM 7。

As you mentioned java.sql.Time is highly deprecated, you can convert it easily to a Calendar instance (since Time extends java.util.Date ) and then use that as per java.util.Date#getTimezoneOffset documentation: 正如您提到的java.sql.Time已被弃用,您可以轻松将其转换为Calendar实例(因为Time扩展了java.util.Date ),然后根据java.util.Date#getTimezoneOffset文档使用它:

Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
long time = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM