[英]moment.js cannot parse date correctly
感謝您的閱讀,我得到了一個日期,該日期從sharepoint返回為10/2/2000 12:00:00 AM
'這不適用於moment.js和語言環境,因此我將其重新解析為一個ISOString,現在是數據' 2000-10-01T22:00:00.000Z
'如在https://github.com/moment/moment/issues/1407中指定。 但是,它仍然會退回到標准javascript Date函數,我也不知道為什么。
下面是我的代碼實現:
瞬間解析代碼
function dayAndFullMonth(dateTime, timezone) {
return moment.tz(dateTime, timezone).format('DD MMM');
}
負責重寫日期的函數
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);
}
}
我的控制台:
任何幫助,將不勝感激。
不知道為什么要調用moment.tz,但是應該是moment('10 / 2/2000 12:00:00 AM')。 這樣可以正確解析並允許您調用format。
編輯后
您需要包括一刻時區,而不僅僅是一刻。 我已經在這里測試了您的代碼: https : //npm.runkit.com/moment-timezone ,它可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.