[英]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.