3个回答
展开全部
const getUTCTime = () => {
const _toFixed = (_num, _length) => {
const _fixLen = (parseInt(_length) || 2) - (_num + '').length;
const _fixStr = _fixLen > 0 ? (0).toFixed(_fixLen - 1).replace('.', '') : '';
败槐弊 return _fixStr + _num;
};
const now = new Date();
const { year, month, day, hour, minute, seconds, milliseconds } = {
year: now.getUTCFullYear(),
month: _toFixed(now.getUTCMonth() + 1),
day: _toFixed(now.getUTCDate()),
hour: _toFixed(now.getUTCHours()),
察族 minute: _toFixed(now.getUTCMinutes()),
明孙seconds: _toFixed(now.getUTCSeconds()),
milliseconds: _toFixed(now.getUTCMilliseconds(), 3),
};
return `${year}-${month}-${day}T${hour}:${minute}:${seconds}.${milliseconds}Z`;
};
console.log(getUTCTime());
// 2019-10-30T08:14:09.002Z
那个return的格式可以随便拼,如果不要UTC时间可以把getUTCHours
改成getHours
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询