iamkun / iamkun/dayjs

dayjs.tz() treats `Date` objects and `ISOString` differently

Open
#2,874 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
If you pass the same date to the function `dayjs.tz` the result is different depending if you use a `Date` object or an ISOString representation.

**Expected behavior**
The result should be the same no matter what you use

```js
const date = new Date();
const dateString = date.toISOString();
// 2025-05-09T20:38:52.929Z

// It shifts the date if you use an iso string
dayjs.tz(dateString, 'America/New_York').toISOString();
// 2025-05-10T00:38:52.929Z

// It doesn't shift the date if you use a date object
dayjs.tz(date, 'America/New_York').toISOString();
// 2025-05-09T20:38:52.929Z

```

I'm not completely sure but this could still be happening in the last version. Here is a screenshot when I was testing this in the console in day.js.org

![Image](https://github.com/user-attachments/assets/521a6484-c5f6-4ee0-80a0-25132742322f)

**Information**
- Day.js Version 1.11.10
- OS: MacOs
- Browser Firefox 138.0.1
- Time zone: GMT-5 Colombia

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.