在前端获取UTC时间戳的方法

1
2
3
4
5
6
7
8
9
10
11
12
13
function getUtcTimestamp() {
const now = new Date();
const utcTimestamp = Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCSeconds(),
now.getUTCMilliseconds()
);
return `${parseInt(utcTimestamp / 1000, 10)}`;
}