문제 설명
Halo 5 API 알 수 없는 타임스탬프 (Halo 5 Api Unknown TimeStamp)
그래서 현재 343 Industries에서 제공하는 Halo 5 API로 작업하고 있습니다. 데이터를 파싱하는 동안 전에 본 적이 없는 타임스탬프를 발견했습니다.
PT1H6M19.6203713S
나는 형식이 무엇인지, JavaScript를 사용하여 변환할 수 있는지 궁금합니다. 이것을 new Date()
생성자에 전달하면 작동하지 않습니다.
참조 솔루션
방법 1:
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')
(by Vannilaknight、trincot)