I’m trying to make a method that return the Date of a timestamp and the conversion isn’t running correctly (Date doesn’t take the whole value ):
String stringDate = "" + operationDate; // operationDate is my timestamp : 1235437200
Long date = Long.valueOf(stringDate); // date worth 1235437200
Date now = new Date(date); // date show me the date of 1235437 (not 1235437200)
How can I make those lines work? I’m not Java specialist but the princip works!
Thanks to read / help me 🙂
EDIT
When I show now (the final date), it gives me Thu Jan 15 08:10:37 CET 1970, and that date is 1235473 in timestamp… and I gave her 12354737200 thanks to the date (Long) value
My import files are
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
EDIT 2 :
public String getHumanDate(){
String stringDate = "" + operationDate;
System.out.println("stringDate => " + stringDate);
Long date = Long.valueOf(stringDate);
System.out.println("date => " + date );
Date now = new Date(date);
System.out.println("now => " + now );
System.out.println("now.toString => " + now.toString());
return now.toString();
}
give me
INFO: stringDate => 1325437200
INFO: date => 1325437200
INFO: now => Fri Jan 16 09:10:37 CET 1970
INFO: now.toString => Fri Jan 16 09:10:37 CET 1970
The date object expects milliseconds instead of a unix timestamp, so you need to multiply by 1000.