【发布时间】:2016-01-21 04:58:29
【问题描述】:
我正在将纪元日期转换为本地日期:
$("time").each(function() {
var date = $(this).text(); // gives me "1325419200000"
newDate = new Date(date); // gives me Invalid Date
});
html:
<td class="date">
<time datetime="{{date}}">{{date}}</time>
</td>
如何将纪元日期转换为本地日期,格式为:'MMM DD, YYYY h:mm:ss A'。我怎样才能做到这一点?
【问题讨论】:
-
你需要
newDate = new Date(parseInt(date));。 -
使用像moment.js这样的库。它会为你省去很多挫折。
-
我希望已经回答了这个问题。看到这个链接stackoverflow.com/questions/4631928/…
标签: javascript jquery