I need it so I can schedule some jobs and reminders according to the user’s timezone location. I can ask users to manually enter their timezone but I would rather not do that extra step for users and just get their timezone automatically from their phones.
Also I was hoping to find a more local solution that doesn’t need an api call to a world clock api.
I’m not sure but it occurred to me that you could get the device hour from Thunkable and then compare it to GMT via an API call and then based on the difference, figure out their timezone. It wouldn’t be perfect, though, because for example here in California we have Daylight Savings which alters the time by an hour.
Hey thanks for the suggestion. That’s exactly what I’m doing now but it’s kinda messy Or prone to bugs due to daylight saving time. Also I was hoping to find a more local solution that doesn’t need an api call to a world clock api.
I would also recommend using an API! You can check out this tutorial for my Reverse Geocoding App - Get Location from Latitude/Longitude that uses the OpenCageData API. This tutorial will return the user’s country, but you can also get the user’s timezone.
Here is their description of the timezone property:
contains the keys name , now_in_dst , offset_sec , offset_string , short_name.
When the coordinates are in a country the name will be of the form Continent/City, the format used by tz database on *nix systems, for example Europe/Lisbon. When the coordinates are not in a country (for example in an ocean) the format will be an offset to/from GMT, for example GMT+2.
Learn more about timezones and how they are typically represented on *nix based systems over on Wikipedia.
I found the easiest way to get the timezone is by using the date() object of the vanilla JS and all what you need is the web viewer instead of web API calls.
Get the number of seconds since 1970 and multiply it by a 1000 and create a new date object from it.
Then use the newDateObject.toLocaleString(“en-US”, {timeZoneName: “short”})
This will display the time zone along with the date in a human readable format.
YES, there is a way to use JavaScript in Thunkable. This is done using the Data Viewer extension to receive data from Thunkable and to send data to Thunkable.
@a.sa.pellaiahj3c & @human APIs are definitely a big topic and can be tricky to understand if it’s your first time seeing them. Thankfully there are lots of great tutorials, both here and on YouTube, that explain this topic.
Here’s a great one from @tatiang to get you started: