I was developing a timetable using dayjs. I would like to set the timetable to show something likes UTC-9 date regardless of user's local time. I tried with dayjs's timezone and utc mode. Both change the time to the correct time but not the date. If I set PC time to other date, dayjs still showing that date instead of UTC-9 date. Thanks.
Asked
Active
Viewed 4,941 times
1
-
1Look at UTC offset,this dependent on UTC plugin to work:https://day.js.org/docs/en/manipulate/utc-offset – Oleg Jun 06 '22 at 05:20
-
@Oleg I tried with utc offset. It only changed the time to correct utc-offset but not the date. For example, let say current utc+10 is Jun 6, I want to show Jun 6 even the user's local time in his computer is Jun 5. – uranium235 Jun 06 '22 at 05:27
-
1did you try like this: https://stackoverflow.com/questions/64006977/dayjs-is-not-converting-timezones-properly – Oleg Jun 06 '22 at 05:31
1 Answers
0
There is a nice example in the day.js documentation itself.
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.tz("2014-06-01 12:00", "America/New_York")
dayjs("2014-06-01 12:00").tz("America/New_York")

Diego Augusto F.
- 64
- 3
-
6Those two ways of creating a date are NOT equivalent. Presenting them this way seems to imply either is acceptable. However, the first will create a date in the given timezone, the second will create a date in UTC, then _convert_ that date to the given timezone. The result of those two operations will not be the same. – devtanc Jul 28 '22 at 01:04