我正在尝试将JSON时间字符串转换为本地时间,如下所示
angular.forEach($scope.calendarData, function(item) {
item.scheduleArray.startTime = new Date(item.scheduleArray.startTime);
item.scheduleArray.endTime = new Date(item.scheduleArray.endTime);
});
startTime = "1970-01-01T08:52:00.000Z"
但是当我执行代码时,它会显示无效的日期。我该如何解决这个问题
答案 0 :(得分:0)
let scheduleArray = {alert: "emailNotification", endTime: "1970-01-01T08:52:00.000Z", expanded: true, startTime: "1970-01-01T11:12:00.000Z", title: "New Schedule"};
let calendarData = [];
calendarData.push({'scheduleArray':scheduleArray});
angular.forEach(calendarData, function(item) {
item.scheduleArray.startTime = new Date(item.scheduleArray.startTime);
item.scheduleArray.endTime = new Date(item.scheduleArray.endTime);
console.log(item.scheduleArray.startTime);
});
console.log(calendarData);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>