Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Integer time stamp into java date [duplicate]

Tags:

java

datetime

I have following time stamp in Integer form

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 in java? So that it would return value:

3/30/12 12:18:43 PM
like image 767
kinkajou Avatar asked May 07 '12 06:05

kinkajou


People also ask

How do I convert time stamps to dates?

The constructor of the Date class receives a long value as an argument. Since the constructor of the Date class requires a long value, we need to convert the Timestamp object into a long value using the getTime() method of the TimeStamp class(present in SQL package).

How do I convert a Date to an integer in Java?

Or, if you really want to convert the 'date' into integer type 06/03/2017 to 06032017 .. you can do something like this. SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy"); System. out. println(Integer.


1 Answers

Assuming its the time since 1/1/1970 in seconds. you can try

String dateAsText = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                          .format(new Date(1333125342 * 1000L));
like image 103
Peter Lawrey Avatar answered Nov 15 '22 23:11

Peter Lawrey