Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting String to Date

Tags:

java

date

parsing

How can I parse the following String "1394133302" which correspond of Date.toString value to a Date value (java utils).

Is it possible with a SimpleDateFormat?

like image 892
JakeRTFM Avatar asked Dec 29 '25 10:12

JakeRTFM


2 Answers

Use code below

    new Date(Long.valueOf("1394133302"))

PS. It seems you date string is in second, maybe you want this(convert it to millesecond!)

    new Date(Long.valueOf("1394133302") * 1000L)
like image 63
Safrain Avatar answered Dec 31 '25 02:12

Safrain


Just feed it back into the Date constructor:

long dateAsLong = Long.parseLong( "1394133302");
Date someDate = new Date(dateAsLong);
like image 34
lreeder Avatar answered Dec 31 '25 03:12

lreeder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!