dayjs timezone is not work in expo app
const a = dayjs(new Date(1384775720)).tz("America/Toronto").format("HH:mm:ss");
const b = dayjs(new Date(1384775720)).tz("Asia/Shanghai").format("HH:mm:ss");
Put the above code into the nodejs running environment. It shows:
{ a: '19:39:35', b: '08:39:35' }
And put it into expo app(https://expo.dev/)
it shows:
00:39:35
Here's my minimal reproduction https://github.com/SteveYuOWO/expo-dayjs-reproduction
I just ripped my hair out for hours trying to figure out why it wasn't working
I just ripped my hair out for hours trying to figure out why it wasn't working
So, is there a solution for this? How does the expo app using dayjs solve the time zone issue in general?
I just ripped my hair out for hours trying to figure out why it wasn't working
So, is there a solution for this? How does the
expo appusingdayjssolve the time zone issue in general?
Seems like this is a known issues:
- https://github.com/iamkun/dayjs/pull/2843
- https://github.com/iamkun/dayjs/issues/1377
I'm going to switch to use a different approach for handling dates and timezones for now
@itajenglish
dayjs currently has no solution. I use a native function to wrap it as a temporary solution.
https://github.com/SteveYuOWO/expo-dayjs-reproduction/pull/1
@itajenglish
dayjs currently has no solution. I use a native function to wrap it as a temporary solution.
https://github.com/SteveYuOWO/expo-dayjs-reproduction/pull/1
Nice! I ended up replacing dayjs with spacetime
@itajenglish dayjs currently has no solution. I use a native function to wrap it as a temporary solution. SteveYuOWO/expo-dayjs-reproduction#1
Nice! I ended up replacing dayjs with spacetime
Cool. Thank you for recommending this open source repo for me. The solution looks better than mine.
dayjs relies on Intl API and IANA db present in nodejs and browsers, but it seems like in RN we don't have it by default. I ended up using spacetime (thanks @itajenglish) lib for timezone conversions
I have problems with this also. I finally use
const deviceOffset = new Date().getTimezoneOffset();
const dayjsUtc = dayjs.utc(myUtcTime);
const dayjsLocal = dayjsUtc.subtract(deviceOffset, "minute");