YC for time zone change?

That integer represents the number of hours between UTC and the users local time.

For example, I’m in Singapore which is UTC+8. So for me it returns -8.
To use it to convert UTC to users local time, you actually need to invert it first and then add it to a date/time using a math column. Here is how I’ve used it in one of my apps:

Screen Shot 2021-11-14 at 2.08.45 PM

Note that I adjusted the code slightly to invert the result, because I want to use it as a correction:

return -(new Date().getTimezoneOffset())/60

Then I use it as follows to convert a UTC timestamp to Users Local time:

Screen Shot 2021-11-14 at 2.10.53 PM

In the example above, T (Timestamp) is a UTC timestamp. So I’m just taking that and adding the UTC offset hours to get local time.

In your case, you may need to use it slightly differently, but hopefully this gives you the idea.

2 Likes