Hi, I want to retrieve the timezone of the person currently viewing the site. the timezone property in wixsite gets the timezone in the site setting. But I want to get the timezone of the viewer. I want to explicitly display the timezones in which we are displaying timing of the events on the site.
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
Use getCurrentGeolocation() in the wix-window API to retrieve the user's IP-based location coordinates. To see how Geolocation works, see Ahmad's excellent Tutorial: Detect Visitors' Geolocation & IP Address and the Example: Google Places.
Once you have the location coordinates, you can get the time zone using an external service such as TimeZoneDB's API:
export function tz(lat, lng, timestamp) { return wixSecretsBackend.getSecret("TimeZoneDB") .then((secret) => { let url = `https://api.timezonedb.com/v2.1/get-time-zone? key=${secret}&format=json&by=position&lat=${lat}&lng=${lng}&time=${timestamp}`; return fetch(url, { method: 'get' }).then((httpResponse) => { if (httpResponse.ok) { return httpResponse.json(); } }); }) .catch((error) => { console.log(error); }); }
Note: you will need to sign up for the TimeZoneDB service to get your own API key.