我被困在下面转换时间戳记,以毫秒为单位在JavaScript中。
我在Postgres的DB时间戳作为
2019-02-04 15:38:22.529
我得到上述时间戳在UI下面的格式,当我从DB读
Mon Feb 04 2019 10:38:22 GMT+0400 (Gulf Standard Time)
我怎么能转换上述UI格式时间戳在JavaScript毫秒?
Date
getTime功能的使用将返回时间毫秒,因为2019-02-04 15:38:22.529
:
const date = new Date("2019-02-04 15:38:22.529");
const time = date.getTime();
console.log(time);
您可以使用getMilliseconds()
如果按照本地时间想毫秒
const date = new Date("2019-02-04 15:38:22.529");
const time = date.getMilliseconds()
console.log(time);
试试这个,在 “Z” 表示UTC + 0:
const time = new Date("2019-02-04T15:38:22.529Z").getTime()