0

So I am currently working with the Halo 5 api provided by 343 Industries. While parsing the data I came across a time stamp that I've never seen before.

PT1H6M19.6203713S

I was curious as to what format it is and if it is possible to convert it using JavaScript. Passing this into the new Date() constructor doesn't work.

1 Answers1

0

This is the ISO_8601 duration format:

The capital letters P, Y, M, W, D, T, H, M, and S are designators for each of the date and time elements and are not replaced.

P is the duration designator (for period) placed at the start of the duration representation.
Y is the year designator that follows the value for the number of years.
M is the month designator that follows the value for the number of months.
W is the week designator that follows the value for the number of weeks.
D is the day designator that follows the value for the number of days.
T is the time designator that precedes the time components of the representation.
H is the hour designator that follows the value for the number of hours.
M is the minute designator that follows the value for the number of minutes.
S is the second designator that follows the value for the number of seconds.

For JavaScript you could use the momentjs library, which can parse these strings. See this question and answer:

...with the moment.duration method:

moment.duration('P1Y2M3DT4H5M6S')
Community
  • 1
  • 1
trincot
  • 317,000
  • 35
  • 244
  • 286