使用 moment.js 显示不准确的日期
Displaying inaccurate date using moment.js
使用nodejs、jade和moment.js
<div class="post-date"> #{entry.published_at} </div>
每次用户创建条目并更新发布日期。它是动态的。
示例:原始日期显示 "Thu Jan 01 2015 08:00:00 GMT+0800 (SGT)"
在网页上,使用 momentjs 转换原始日期,因此仅显示 2015 年 1 月 1 日。
脚本
$('.post-date').each(function(i, e) {
var date = $(this).text();
$(this).html(moment(date).format("DD MMMM YYYY"));
});
但这显示的日期不正确,例如:2015 年 1 月 2 日。
无法理解为什么它显示的日期不正确。
感谢帮助。
可能是时区的原因。
看看这个 link:http://momentjs.com/timezone/
@MattJohnson - 建议格式化日期而不是解析。
使用nodejs、jade和moment.js
<div class="post-date"> #{entry.published_at} </div>
每次用户创建条目并更新发布日期。它是动态的。
示例:原始日期显示 "Thu Jan 01 2015 08:00:00 GMT+0800 (SGT)" 在网页上,使用 momentjs 转换原始日期,因此仅显示 2015 年 1 月 1 日。
脚本
$('.post-date').each(function(i, e) {
var date = $(this).text();
$(this).html(moment(date).format("DD MMMM YYYY"));
});
但这显示的日期不正确,例如:2015 年 1 月 2 日。
无法理解为什么它显示的日期不正确。
感谢帮助。
可能是时区的原因。
看看这个 link:http://momentjs.com/timezone/
@MattJohnson - 建议格式化日期而不是解析。