开发者

How to change a long variable to a Timestamp in Java?

开发者 https://www.devze.com 2023-03-04 08:45 出处:网络
How do I change a long variable to a Timestamp variable? I can convert it to a String but I need to convert it to开发者_如何学Go Timestamp in order to use it in a database.Timestamp extends java.util.

How do I change a long variable to a Timestamp variable? I can convert it to a String but I need to convert it to开发者_如何学Go Timestamp in order to use it in a database.


Timestamp extends java.util.Date and it has a constructor that accepts a long.

Like this:

import java.sql.Timestamp;

public class Main {

    public static void main(String[] args) {
        long inputLong = 1234567890l * 1000l;  // Constructor expects a milliseconds value

        Timestamp outputTimestamp = new Timestamp(inputLong);

        System.out.println (outputTimestamp);
    }

}


I don't know Java, but an internet search suggests that Timestamp has a constructor which takes a long:

So, you can do something like this, perhaps:

Timestamp t = new Timestamp(l);

For more information, see http://download.oracle.com/javase/6/docs/api/java/sql/Timestamp.html.


Use Timestamp. it has a constructor that receives long as the only parameter.

0

精彩评论

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