Java Convert Date to TimestampWe can convert Date to Timestamp in java using constructor of java.sql.Timestamp class. The constructor of Timestamp class receives long value as an argument. So you need to convert date into long value using getTime() method of java.util.Date class. You can also format the output of Timestamp using java.text.SimpleDateFormat class. Constructor of Timestamp class: getTime() method of Date class: Java Date to Timestamp ExampleLet's see the simple example to convert Date to Timestamp in java. Test it NowOutput: 2017-11-02 01:59:30.274 You can format the Timestamp value using SimpleDateFormat class. Let's see the example of display Timestamp value without milliseconds. Test it NowOutput: 2017-11-02 02:04:03 Next TopicJava Timestamp to Date |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India