简体   繁体   中英

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. I can not use getTime() function. I noticed that there is a deprecated function getTimeZoneOffset . So, I don't want to use it. What else can I use? I am also using JVM 7. Thanks in advance.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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