1

I am looking for a way to get minutes only from a date in string (coming from toISOString).

When using Date object, I was using getTime(), but dont think there is a direct method available for ISO format.

Would I need to extract strings directly from ISO format, as its just a string?

Code:

var depTime = new Date(1222332000).toISOString();

This gives me "1970-01-15T03:32:12.000Z", so what is a good way to get minutes which is "32".

whyAto8
  • 1,660
  • 4
  • 30
  • 56

3 Answers3

3

You can use getMinutes() from the date object:

var d = new Date('1970-01-15T03:32:12.000Z');
console.log(d.getMinutes());

This is the right method, but, if there are issues with the Time Zone, you can parse the string:

var depTime = new Date(1222332000).toISOString();
console.log(depTime.split(":")[1]);  // 32
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

You can use

deptime.getMinutes(); // 32

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes

0

Since it's just a string, regex should work just fine.

T\d+:(\d+)
Tyler
  • 740
  • 9
  • 27