javascript 类型错误:dayjs.utc不是函数

txu3uszq  于 2023-01-01  发布在  Java
关注(0)|答案(2)|浏览(386)

我收到此错误
dayjs.utc不是函数
下面是我的代码

const dayjs = require('dayjs')

console.log('utc time',dayjs.utc())
8zzbczxx

8zzbczxx1#

这是因为使用dayjs的方法不正确。请参阅:

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')

你犯的错误:

var utc = require('dayjs')

修复我分享:

var utc = require('dayjs/plugin/utc')

出发地:https://day.js.org/docs/en/plugin/utc

ljsrvy3e

ljsrvy3e2#

修复:我尝试了此方法,它有效:

const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
dayjs.extend(utc)

console.log('utc time',dayjs.utc())

参考文件https://day.js.org/docs/en/plugin/utc

相关问题