开发者

Convert Time variable to milliseconds

I am having a variable which is called from_time and I am reading the infor from the开发者_运维知识库 DB.

Time from_time = rs.getTime("nfrm_time");

How to convert the from_time into milliseconds and seconds?

Thanks for the help


java.sql.Time extends java.util.Date, and has getTime() method which returns millis.


You should use the method getTime():

public class Main
{
    public static void main(String[] args)
    {
        Time t = new Time(System.currentTimeMillis());
        long l = t.getTime();
    }
}


Once you have the millis as indicated by Bozho, you can use java.util.concurrent.TimeUnit to rather easily convert to seconds (and hours, days, etc).

Even though it's actually in the concurrent package, I found this to be of great use for general cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜