Scene:
Service-side output JSON:
{"Msglist": [{"MsgID": 1066, "Sendertype": "S", "SenderID": "The", "sender": "The", "Receivenum": 4, "Sendtime" : 1394422138000, "Msgflag": 1, "content": "{Title": "Cao", "Content": "Kao"}, "ContentType": 1},{"MsgID": 1067, " Sendertype ":" S "," SenderID ":" The "," Sender ":" 4 "," Receivenum ":" "," Sendtime ": 1395131639000," Msgflag ": 1," content ":" { "Title": "Cao", "Content": "Chinese Contents"}, "ContentType": 1}], "Noofpages": 1, "CurrentPage": 1}
The Sendtime value is a Java timestamp
JavaScript formats the timestamp, displaying the date as Yyyy-mm-dd h:m:s code as follows:
The code is as follows |
Copy Code |
function Formattime (javatimestamp) { var dt = new Date (javatimestamp); var dt = new Date (unixtimestamp*1000);
var hours = pad (dt.gethours ()); var minutes = pad (dt.getminutes ()); var seconds = pad (Dt.getseconds ()); var years = Dt.getfullyear (); var months = pad (Dt.getmonth () +1); var days = pad (dt.getdate ());
Return years + "-" + Months + "-" + Days + "" +hours + ":" + minutes + ":" + seconds; } function Pad (value) { Return (value.tostring (). length < 2)? ' 0 ' + value:value; } |
Call:
1394422138000 is a Java timestamp, Unix timestamp =java time stamp/1000
The code is as follows |
Copy Code |
Formattime (1394422138000) |
With a simple example
If you want to: 2010-10-20 10:00:00 in this format
code is as follows |
copy code |
<script Function Getlocaltime (ns) { return new Date (parseint (NS * 1000). toLocaleString (). Replace (/year | month/g, "-"). Replace (/day/g, ""); } Alert (Getlocaltime (1177824835)); </script> |