Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the unix timestamp didnt not pick up the timezone change correctly #1159

Closed
jianwenl opened this issue Oct 21, 2020 · 8 comments · Fixed by #1160
Closed

the unix timestamp didnt not pick up the timezone change correctly #1159

jianwenl opened this issue Oct 21, 2020 · 8 comments · Fixed by #1160
Labels

Comments

@jianwenl
Copy link

Describe the bug
How to get the correct time stamp with a time on a specific timezone ?
I want to check the unix timestamp for 10/15/2020 12:30 PM at Denver, but neither of the approaches (3 and 4) works.

//Los Angeles (correct)
console.log("local notz:", dayjs("10/15/2020 12:30 PM").unix().toString());
// local notz:1602790200
2.
//Los Angeles (wrong)
console.log("local:", dayjs.tz("10/15/2020 12:30 PM").unix().toString());
// local: 1602815400
3.
// Denver (wrong)
console.log(
"denver:",
dayjs.tz("10/15/2020 12:30 PM", "America/Denver").unix().toString()
);
//denver: 1602811800
4.
// Denver (wrong)
console.log(
"denver sep:",
dayjs("10/15/2020 12:30 PM").tz("America/Denver").unix().toString()
);
//denver sep: 1602790200

Expected behavior
A clear and concise description of what you expected to happen.

1.1602790200
2.1602790200
3.1602793800
4.1602793800

Information

  • Day.js Version [e.g. v1.9.3]
  • OS: [e.g. macOS 10.15.7]
  • Browser [e.g. chrome 86]
  • Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]
@iamkun
Copy link
Owner

iamkun commented Oct 21, 2020

You can use dayjs.tz('2020/10/15 10:30', 'America/Denver').unix() to get the correct result 1602779400 at this moment.

We will support custom format parsing in dayjs.tz in a short time.

@jianwenl
Copy link
Author

jianwenl commented Oct 21, 2020

10:30

Did you mean 11:30 am for my current time at LA timezone to indicate 12:30pm at Denver ? Is there anyway to calculate this 1 hour difference with dayjs or I need to calculate it by my self ? Thank you.

@iamkun
Copy link
Owner

iamkun commented Oct 21, 2020

Sorry for the typo, it should be dayjs.tz('2020/10/15 12:30', 'America/Denver').unix() and resulting 1602786600

@jianwenl
Copy link
Author

jianwenl commented Oct 21, 2020

Sorry for the typo, it should be dayjs.tz('2020/10/15 12:30', 'America/Denver').unix() and resulting 1602786600

Which this '12:30' refers to ? '12:30 am' or '12:30 pm' ? I tired all '12:30' '12:30 am' '12:30 pm', but they gave me three different timestamps.

@iamkun
Copy link
Owner

iamkun commented Oct 21, 2020

it refers to '12:30 am', I think

@jianwenl
Copy link
Author

it refers to '12:30 am', I think

They are different :
'2020/10/15 12:30' => 1602786600
'2020/10/15 12:30 am' => 1602768600
'2020/10/15 12:30 pm' => 1602811800

@iamkun
Copy link
Owner

iamkun commented Oct 21, 2020

As I said above, we only support this format 2020/10/15 12:30 at present. More available parsing option will be available in #1160.

You can treat 2020/10/15 12:30 as 12:30 am and 2020/10/15 24:30 as 12:30 pm in this version.

However, I do think 12:00 am and 12:00 pm should be the same time.

iamkun pushed a commit that referenced this issue Oct 23, 2020
## [1.9.4](v1.9.3...v1.9.4) (2020-10-23)

### Bug Fixes

* Add descriptions to types ([#1148](#1148)) ([9a407a1](9a407a1))
* add devHelper plugin ([#1163](#1163)) ([de49dc8](de49dc8))
* Fix Hungarian (hu) locale ([#1112](#1112)) ([ab13754](ab13754))
* fix minMax plugin parsing empty array bug ([#1062](#1062)) ([368108b](368108b))
* update adding/subtracting Duration from Dayjs object ([#1156](#1156)) ([f861aca](f861aca))
* update en-NZ locale to use proper ordinal formatting function ([#1143](#1143)) ([fcdbc58](fcdbc58))
* update localeData plugin type ([#1116](#1116)) ([ee5a4ec](ee5a4ec))
* update timezone plugin to support custom parse format ([#1160](#1160)) ([48cbf31](48cbf31)), closes [#1159](#1159)
* update timezone plugin to support keepLocalTime ([#1161](#1161)) ([1d429e5](1d429e5)), closes [#1149](#1149)
@iamkun
Copy link
Owner

iamkun commented Oct 23, 2020

🎉 This issue has been resolved in version 1.9.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this issue May 10, 2022
## [1.9.4](iamkun/dayjs@v1.9.3...v1.9.4) (2020-10-23)

### Bug Fixes

* Add descriptions to types ([#1148](iamkun/dayjs#1148)) ([9a407a1](iamkun/dayjs@9a407a1))
* add devHelper plugin ([#1163](iamkun/dayjs#1163)) ([de49dc8](iamkun/dayjs@de49dc8))
* Fix Hungarian (hu) locale ([#1112](iamkun/dayjs#1112)) ([ab13754](iamkun/dayjs@ab13754))
* fix minMax plugin parsing empty array bug ([#1062](iamkun/dayjs#1062)) ([368108b](iamkun/dayjs@368108b))
* update adding/subtracting Duration from Dayjs object ([#1156](iamkun/dayjs#1156)) ([f861aca](iamkun/dayjs@f861aca))
* update en-NZ locale to use proper ordinal formatting function ([#1143](iamkun/dayjs#1143)) ([fcdbc58](iamkun/dayjs@fcdbc58))
* update localeData plugin type ([#1116](iamkun/dayjs#1116)) ([ee5a4ec](iamkun/dayjs@ee5a4ec))
* update timezone plugin to support custom parse format ([#1160](iamkun/dayjs#1160)) ([48cbf31](iamkun/dayjs@48cbf31)), closes [#1159](iamkun/dayjs#1159)
* update timezone plugin to support keepLocalTime ([#1161](iamkun/dayjs#1161)) ([1d429e5](iamkun/dayjs@1d429e5)), closes [#1149](iamkun/dayjs#1149)
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this issue May 10, 2022
## [1.9.4](iamkun/dayjs@v1.9.3...v1.9.4) (2020-10-23)

### Bug Fixes

* Add descriptions to types ([#1148](iamkun/dayjs#1148)) ([9a407a1](iamkun/dayjs@9a407a1))
* add devHelper plugin ([#1163](iamkun/dayjs#1163)) ([de49dc8](iamkun/dayjs@de49dc8))
* Fix Hungarian (hu) locale ([#1112](iamkun/dayjs#1112)) ([ab13754](iamkun/dayjs@ab13754))
* fix minMax plugin parsing empty array bug ([#1062](iamkun/dayjs#1062)) ([368108b](iamkun/dayjs@368108b))
* update adding/subtracting Duration from Dayjs object ([#1156](iamkun/dayjs#1156)) ([f861aca](iamkun/dayjs@f861aca))
* update en-NZ locale to use proper ordinal formatting function ([#1143](iamkun/dayjs#1143)) ([fcdbc58](iamkun/dayjs@fcdbc58))
* update localeData plugin type ([#1116](iamkun/dayjs#1116)) ([ee5a4ec](iamkun/dayjs@ee5a4ec))
* update timezone plugin to support custom parse format ([#1160](iamkun/dayjs#1160)) ([48cbf31](iamkun/dayjs@48cbf31)), closes [#1159](iamkun/dayjs#1159)
* update timezone plugin to support keepLocalTime ([#1161](iamkun/dayjs#1161)) ([1d429e5](iamkun/dayjs@1d429e5)), closes [#1149](iamkun/dayjs#1149)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants