在客户端解析Unix时间戳到日期字符串

时间:2011-12-31 22:05:40

标签: c# javascript

res.SentTime.substring(6,19)    

“1318319100000”

var date = new Date();
date.setTime(res.SentTime.substring(6,19));

1318319100000

为什么不解析日期字符串?

1 个答案:

答案 0 :(得分:3)

将时间戳乘以1000。你会得到mili秒。将它传递给JS中的Date构造函数。

在你的代码中执行此操作,

var date = new Date(parseInt(res.SentTime.substring(6,19),10)*1000);