简体   繁体   English

使用moment.js显示不正确的日期

[英]Displaying inaccurate date using moment.js

Using nodejs, jade and moment.js 使用nodejs,jade和moment.js

<div class="post-date"> #{entry.published_at} </div>

Every time user creates entry and the date published is updated. 每次用户创建条目并更新发布日期。 It is dynamic. 它是动态的。

Example: Raw date shows "Thu Jan 01 2015 08:00:00 GMT+0800 (SGT)" On web page, converting the raw date with momentjs so only Jan 01 2015 is displayed. 示例:原始日期显示为“ Thu Jan 01 2015 08:00:00 GMT + 0800(SGT)”在网页上,使用momentjs转换原始日期,因此仅显示2015年1月1日。

Script 脚本

   $('.post-date').each(function(i, e) {
      var date = $(this).text();
      $(this).html(moment(date).format("DD MMMM YYYY"));
    });

But this displays incorrect date, for example: Jan 02 2015. 但这显示的日期不正确,例如:2015年1月2日。

Couldn't figure why it is displaying incorrect date. 无法弄清楚为什么显示的日期不正确。

Help appreciated. 帮助表示赞赏。

@MattJohnson-建议格式化日期而不是解析日期。

Maybe it could be because of Timezone. 可能是因为时区。

Take a look into this link: http://momentjs.com/timezone/ 看一下此链接: http : //momentjs.com/timezone/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM