我的控制台:
相同,但没有新的日期构造函数:
可能出了什么问题?
PS:这与项目无关,因为我在 momentjs.com 的控制台中得到相同的结果
编辑: 要轻松重现,请访问 momentjs.com,打开控制台,输入:
moment().calendar('2016-11-27T07:31:29.000+0000'); // expecting "Sunday at 9:58 AM" getting "Tuesday at 9:58 AM"
moment().calendar('2016-11-28T07:31:29.000+0000'); // expecting "Yesterday at 9:58 AM" getting "Tomorrow at 9:58 AM"
moment().calendar('2016-11-29T07:31:29.000+0000'); // this is correct "Today at 9:58 AM"
moment().calendar('2016-11-30T07:31:29.000+0000'); // expecting "Tomorrow at 9:58 AM" getting "Yesterday at 9:58 AM"
最佳答案
在 docs它说:
moment().calendar(referenceTime);
日历时间显示相对于给定引用时间的时间(默认为现在),但与 moment#fromNow 略有不同
所以你得到的结果是正确的,因为你的字符串时间是引用。
为了获得正确的结果,请使用:
moment('2016-11-30T07:31:29.000+0000').calendar();
关于javascript - Moment.js 反向给出明天和昨天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40861519/