Search code examples
javascriptnode.jsutcdayjs

TypeError: dayjs.utc is not a function


I am getting this error

dayjs.utc is not a function

Here is my code

const dayjs = require('dayjs')

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

Solution

  • Fix: I tried this it's working:

    const dayjs = require('dayjs')
    const utc = require('dayjs/plugin/utc')
    dayjs.extend(utc)
    
    console.log('utc time',dayjs.utc())
    

    Refer docs https://day.js.org/docs/en/plugin/utc