How to convert TimeStamp to Date in Java? How to convert TimeStamp to Date in Java? java java

How to convert TimeStamp to Date in Java?


Just make a new Date object with the stamp's getTime() value as a parameter.

Here's an example (I use an example timestamp of the current time):

Timestamp stamp = new Timestamp(System.currentTimeMillis());Date date = new Date(stamp.getTime());System.out.println(date);


// timestamp to Datelong timestamp = 5607059900000; //Example -> in msDate d = new Date(timestamp );// Date to timestamplong timestamp = d.getTime();//If you want the current timestamp :Calendar c = Calendar.getInstance();long timestamp = c.getTimeInMillis();


Just:

Timestamp timestamp = new Timestamp(long);Date date = new Date(timestamp.getTime());