如何从日期字符串中获取总分钟数?

How to get the total number of minutes from a date string?

从后端,我正在检索此字符串作为日期:"2017-08-16T18:35:41.611Z2017-08-16T13:35:41.611"

如何从此字符串中提取总分钟数?我尝试了以下方法:

let date = new Date("2017-08-16T18:35:41.611Z2017-08-16T13:35:41.611");
let minutes = date.getMinutes();
console.log(minutes);

但是 date 记录为 Invalid Dateminutes 记录为 NaN。有什么想法吗?

您的后端向您发送两倍的日期 2017-08-16T18:35:41.611Z2017-08-16T13:35:41.611

如果你不能修改后端服务,你可以用Z拆分它们,然后执行你说的功能:

let date = new Date("2017-08-16T18:35:41.611Z2017-08-16T13:35:41.611".split("Z")[0]);
let minutes = date.getMinutes();
console.log(minutes);

在你的日期字符串中我看到两个日期。

dateString = "2017-08-16T18:35:41.611Z2017-08-16T13:35:41.611"

dates  = x.split('Z')

console.log("date1 :", new Date(dates[0])
console.log("date1 :", new Date(dates[1])

希望对您有所帮助