Hello, I was under the impressions that calling moment() should return local timestamp by default. However, that is not what Iām getting running this code. Can someone please clarify this for me? Thank you.
Hey @Mariusz_Kolaszewski ,
What are you expecting this code to output here? It looks like lines 2 and 3 get the current time in America/New_York and Africa/Abidjan (whatās being detected as your current TZ).
Hey Mitchel, my TZ is not āAfrica/Abidjanā. I expect moment() to return local timezone āAmerica/New Yorkā.
Thatās almost certainly the explanation for why youāre seeing moment() returning a time zone youāre not expecting. Line 8 indicates that itās detecting your local time zone as Africa/Abidjan. Are you running a VPN or do you have your computer set to a specific time zone?
For reference, this is what I see when running your code. Iām on NY time zone so moment() and moment.tz(āAmerica/New_Yorkā) return the same value as expected.
Running the following outside of Retool returns correct timezone.
So this is definitely a Retool issue.
Hey @Mariusz_Kolaszewski - thanks for reaching out. The JS code you're writing is in a workflow block and, as such, gets executed within the context of our backend server where Intl.DateTimeFormat().resolvedOptions().timeZone resolves to UTC. This is the expected behavior so I don't think there's necessarily anything wrong here. Let me know if you have any follow up questions!
Hey Darren, I also get UTC when running moment() inside the app. Which is not consistent with whatās reported by @Mitchel_Smith who is getting āAmerica/New Yorkā.
Hey @Mariusz_Kolaszewski! The moment library has a UTC method you can use to get local time. Just replace item.CREATED with your actual time string you are trying to localize:
{{ moment.utc(item.CREATED).format('hh:mm:ss') }}
Ah thanks for checking and confirming, @Mariusz_Kolaszewski. There are definitely ways around this, but the behavior that you're describing certainly sounds unexpected. Are you loading any custom JS libraries into your app environment? Do you observe the same behavior in a brand new empty app?


