首页 > 解决方案 > Date.parse() 无法识别 hh:mm:ss.sss

问题描述

我正在尝试callLength使用以下函数将时间字符串转换为毫秒,但返回值为NaN.

我哪里错了?

export const timeFunc = callLength => {
  console.log(callLength); // prints "00:00:32.000"
  const startingTime = Date.parse('1970-01-01T00:' + callLength + 'Z') // should print length in milliseconds?
  console.log(startingTime); // prints NaN
}

标签: javascript

解决方案


你增加了两次时间。

Date.parse('1970-01-01T00:' + "00:00:32.000" + 'Z')

推荐阅读