Java Convert Timestamp to DateWe can convert Timestamp to Date in java using constructor of java.util.Date class. The constructor of Date class receives long value as an argument. So, you need to convert Timestamp object into long value using getTime() method of java.sql.Timestamp class. Let's see the constructor of Date class and signature of getTime() method. Constructor of Date class: getTime() method of Timestamp class: Java Timestamp to Date ExampleLet's see the simple example to convert Timestamp to Date in java. Test it NowOutput: Thu Nov 02 02:29:07 IST 2017 The Timestamp class extends Date class. So, you can directly assign instance of Timestamp class into Date. In such case, output of Date object will be like Timestamp. But, it is not suggested by Java Doc because you may loose the milliseconds or nanoseconds of data. Test it NowOutput: 2017-11-02 02:36:57.204 Next TopicJava Binary to Decimal |
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