Skip to content

Incorrect format() output after using utcOffset(0, true) #2799

@iHaPBoy

Description

@iHaPBoy

Describe the bug

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';

dayjs.extend(utc);

const timezoneOffset = 0;
const startDate = dayjs('2025-01-06', 'YYYY-MM-DD').utcOffset(timezoneOffset, true);
const endDate = dayjs('2025-01-09', 'YYYY-MM-DD').utcOffset(timezoneOffset, true);
let d = startDate;
while (!d.isAfter(endDate)) {
  console.log('date', d.toISOString(), d.utcOffset(), d.format('YYYY-MM-DD'));
  d = d.add(1, 'day');
}

output:

date 2025-01-06T00:00:00.000Z 0 2025-01-06
date 2025-01-07T00:00:00.000Z 0 2025-01-06
date 2025-01-08T00:00:00.000Z 0 2025-01-07
date 2025-01-09T00:00:00.000Z 0 2025-01-08

Expected behavior

date 2025-01-06T00:00:00.000Z 0 2025-01-06
date 2025-01-07T00:00:00.000Z 0 2025-01-07
date 2025-01-08T00:00:00.000Z 0 2025-01-08
date 2025-01-09T00:00:00.000Z 0 2025-01-09

Information

  • Day.js Version v1.11.13
  • OS: macOS
  • Node.js v20.12.0
  • Time zone: UTC+8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions