我有一个带有iso格式日期的json响应。我正在尝试将其转换为日期格式并将其本地化为瑞典语。 我想我已经接近了,但是我缺少转换的步骤。我在控制台中收到以下代码的“无效日期”:
var callback = function (text, video) {
parsedData = JSON.parse(text);
var sortedParsedData = _.sortBy(parsedData, 'publishedAt')
initVideo(sortedParsedData,listEl);
console.log('parsed', sortedParsedData);
var videoDate = sortedParsedData[0].publishedAt;
var localDate = new Date(videoDate);
console.log(localDate.toLocaleDateString('se-SE')); //this results in 'Invalid Date'
}
function getAjax(callback, video) {
setTimeout(function () {
callback(JSON.stringify([{
"id": "vid1",
"title": "Lorem ipsum",
"description": "This is a great day for a workout",
"author": "Lars Ohlsson",
"publishedAt": "2018-05-12T10:11:05+99:00",
"imageUrl": "img/as.png",
"thumbnailUrl": "img/as-500-150x150.png",
"views": 48224,
"tags": [
"workout",
"friends"
],
"contentUrl": "video/tears-of-steel-battle-clip-medium.mp4",
"thumb-url": "#"
}, {
...
}]), video)
}, 100)
}