问题
I am using the following method to return a formatted date as say 07:00AM, Apr 12 2016
. But I keep getting 01:41PM, Sat, Jan 17 1970
. Say for example my timestamp is 1460469600
.
Here is my method.
public static String formattedDate(long timestamp) {
DateTime date = new DateTime(timestamp);
String formatted= date.toString("hh:mma, EEE, MMM dd yyyy");
return formatted;
}
回答1:
Your timeStamp is wrong. It doesnt represent the correct time in millis. YOur timeStamp refers to 01:41PM, Sat, Jan 17 1970.
You can check what time date the timeinmillis (TimeStamp) refers to from this site.
http://currentmillis.com/
To get the correct time from unix time stamp just change your DateTime date = new DateTime(timestamp); into
DateTime date = new DateTime(timestamp*1000);
Because unix time gives timpestamp in seconds and we need millis here.
回答2:
Query to get timestamp in milliseconds :
select UNIX_TIMESTAMP(yourtimestamp) *1000 from tablename.
this gives time stamp in milliseconds in mysql
来源:https://stackoverflow.com/questions/36556875/unix-timestamp-keeps-returning-jan-17-1970-in-datetime