offset = new Date().getTimezoneOffset();
This gives you timezone offset, based on computer clock or browser's timezone. Is there any way to get timezone offset based on ip location?
offset = new Date().getTimezoneOffset();
This gives you timezone offset, based on computer clock or browser's timezone. Is there any way to get timezone offset based on ip location?
There's an API at http://ip-api.com/ that will return latitude, longitude, and timezone for an IP address. The timezone is in the format "America/New_York" or the like, which you'll need moment.js and moment-timezone.js to turn into an actual hour-and-minute offset.
Keep in mind because of rules for Daylight Saving, the timezone offset for a given location isn't necessarily a constant -- that's why named timezones like "America/New_York" are used, and why you need something like moment.js to interpret the timezone offset for any particular time.
You can use momentjs and get the user's zone like this:
const moment = require('moment-timezone');
let zone = moment.tz.guess()
Once you get the zone you can use it to get the timezone:
const tzn = moment().tz(zone).format('DD-MMM-YYYY HH:mm:ss Z');
For more clarification you can check momentjs docs: https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/