[英]moment.js cannot parse date correctly
Thanks for reading, I got a date that get's returned from sharepoint as ' 10/2/2000 12:00:00 AM
' This didn't work with moment.js and locales so I reparsed it to a ISOString, now the data ' 2000-10-01T22:00:00.000Z
' as specified as in: https://github.com/moment/moment/issues/1407 . 感谢您的阅读,我得到了一个日期,该日期从sharepoint返回为10/2/2000 12:00:00 AM
'这不适用于moment.js和语言环境,因此我将其重新解析为一个ISOString,现在是数据' 2000-10-01T22:00:00.000Z
'如在https://github.com/moment/moment/issues/1407中指定。 However it will still fallback to the standard javascript Date function and I have no idea why. 但是,它仍然会退回到标准javascript Date函数,我也不知道为什么。
Below is my code implementation: 下面是我的代码实现:
Code for parsing in momentJs 瞬间解析代码
function dayAndFullMonth(dateTime, timezone) {
return moment.tz(dateTime, timezone).format('DD MMM');
}
The function responsible for rewriting the date 负责重写日期的函数
function rewriteDates()
{
var endPartArray = 0;
for(var i = 0; i< vm.birthdays.length; i++)
{
var birthday = sharepointservice.getProperty(vm.birthdays[i].Cells, 'Birthday');
console.log(birthday);
var cleanBirthday = new Date(birthday.split(' ')[0]).toISOString();
console.log(cleanBirthday);
var dutchDates = dateservice.dayAndFullMonth(cleanBirthday, "Europe/Amsterdam");
console.log(dutchDates);
}
}
my console: 我的控制台:
Any help would be appreciated. 任何帮助,将不胜感激。
Not sure why you're calling moment.tz, but it should just be moment('10/2/2000 12:00:00 AM'). 不知道为什么要调用moment.tz,但是应该是moment('10 / 2/2000 12:00:00 AM')。 That will parse correctly and allow you to call format. 这样可以正确解析并允许您调用format。
After Edit 编辑后
You need to include moment-timezone, not just moment. 您需要包括一刻时区,而不仅仅是一刻。 I've tested your code here: https://npm.runkit.com/moment-timezone and it works fine. 我已经在这里测试了您的代码: https : //npm.runkit.com/moment-timezone ,它可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.