Convert Integer timestamp to java date

I have the following timestamp in form Integer

1333125342

I can convert it using SQL:

select DATEADD(ss, FlOOR(1333089223/86400)*86400, '1970-01-01 00:00:00') AS Date  

How to convert it to java? To return a value:

3/30/12 12:18:43 PM
+5
source share
3 answers

Assuming this time is from 1/1/1970 in seconds. you can try

String dateAsText = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                          .format(new Date(1333125342 * 1000L));
+17
source

if the value in milliseconds is the number of milliseconds elapsed since January 1, 1970 00:00:00.000 GMT

just use

new java.util.Date(millis);

and if you need it in a specific format

3/30/12 12:18:43 PM

then use SimpleDateFormatto format Datefor the desired formattedString

+2
source

This timestamp contains seconds elapsed from 1970-1-1: 00 UTC.

To convert it to Java Date, create a new DateObject (see Java document) and call setTime(). Note that it setTimeexpects milliseconds instead of seconds, so you will need to multiply your timestamp by 1000.

The method toString()gives something readable.

0
source

All Articles