-1

From the back-end, I am retrieving this string as a date: "2017-08-16T18:35:41.611Z2017-08-16T13:35:41.611"

How can I extract the total number of minutes from this string? I tried the following:

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

But date logs as Invalid Date and minutes logs as NaN. Any ideas?

Ralph David Abernathy
  • 5,230
  • 11
  • 51
  • 78

2 Answers2

2

Your backend is sending you twice the date 2017-08-16T18:35:41.611Z2017-08-16T13:35:41.611

If you can't modify the backend service, you could split them by the Z and then do the function you said:

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);
Frankusky
  • 1,040
  • 9
  • 18
  • This will change the timezone used for parsing from Z to local, and the required result would be `date.getHours()*60 + date.getMinutes()`. – RobG Aug 16 '17 at 01:34
1

In your date string I see two dates.

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])

hope that helps

not_python
  • 904
  • 6
  • 13
  • Unless the host system is set to UTC+0000, this changes the timezone of the first date. – RobG Aug 16 '17 at 01:40