#1241·dayjs

Creating a UTC object from a dayjs object fails

Author: JuanMMECreated Nov 26, 2020Updated Aug 25, 2026
Labels☢️Bug

Describe the bug Do this:

let plainDate = '2018-02-20T23:59:59.000Z'; let obj = dayjs(plainDate); console.log(1, dayjs.utc(plainDate).toISOString()); console.log(1, dayjs.utc(obj).toISOString()); console.log(2, dayjs(plainDate).utc().toISOString()); console.log(2, dayjs(obj).utc().toISOString());

The second console.log will print an incorrect date (today at 00:00:00) instead of the original date passed. Doing this however:

console.log(1, dayjs.utc(obj.toDate()).toISOString());

Seems to work just fine.

Expected behavior Creating UTC Dayjs objects should work the same way as creating regular dayjs objects, which means passing a dayjs object as a parameter should work just fine. Instead, creating a dayjs object from a dayjs object works only if you do dayjs() but not dayjs.utc().

Information

  • Day.js Version 1.9.6
  • OS: Windows 10
  • Browser Edge 87
  • Time zone: CET