var utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
// default local time
dayjs().format() //2019-03-06T17:11:55+08:00
// UTC mode
dayjs.utc().format() // 2019-03-06T09:11:55Z
// convert local time to UTC time
dayjs().utc().format() // 2019-03-06T09:11:55Z
// While in UTC mode, all display methods will display in UTC time instead of local time.
// And all getters and setters will internally use the Date#getUTC* and Date#setUTC* methods instead of the Date#get* and Date#set* methods.
dayjs.utc().isUTC() // true
dayjs.utc().local().format() //2019-03-06T17:11:55+08:00
dayjs.utc('2018-01-01', 'YYYY-MM-DD')
2条答案
按热度按时间8zzbczxx1#
这是因为使用
dayjs
的方法不正确。请参阅:你犯的错误:
修复我分享:
出发地:https://day.js.org/docs/en/plugin/utc
ljsrvy3e2#
修复:我尝试了此方法,它有效:
参考文件https://day.js.org/docs/en/plugin/utc