在JavaScript中,我无法将时间戳转换为毫秒以下。
我在Postgres DB中将时间戳记为
2019-02-04 15:38:22.529
当我从数据库中读取数据时,会在UI中以以下格式超过时间戳
Mon Feb 04 2019 10:38:22 GMT+0400 (Gulf Standard Time)
如何在JavaScript中将上述UI格式时间戳转换为毫秒?
答案 0 :(得分:2)
使用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);
答案 1 :(得分:1)
尝试一下,“ Z”表示UTC + 0:
const time = new Date("2019-02-04T15:38:22.529Z").getTime()
答案 2 :(得分:1)
如果要根据当地时间设置毫秒,则可以使用getMilliseconds()
const date = new Date("2019-02-04 15:38:22.529");
const time = date.getMilliseconds()
console.log(time);