xxxxxxxxxx
function calcTime(city, offset) {
d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
nd = new Date(utc + (3600000*offset));
return "The local time in " + city + " is " + nd.toLocaleString();
}
// get Bombay time
console.log(calcTime('Bombay', '+5.5'));
// get Singapore time
console.log(calcTime('Singapore', '+8'));
// get London time
console.log(calcTime('London', '+1'));
xxxxxxxxxx
function getTimeFromTimezone(offset) {
const currentDate = new Date() //get current time to calculate the UTC time
let utc = currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000) //calculates the UTC time
let nd = new Date(utc + (3600000*offset)) // get the current timezone with the offset
return nd
}
getTimeFromTimezone('+5.5').toLocaleString()
getTimeFromTimezone('-3').toLocaleString()
xxxxxxxxxx
if (!sessionStorage.getItem('timezone')) {
var tz = jstz.determine() || 'UTC';
sessionStorage.setItem('timezone', tz.name());
}
var currTz = sessionStorage.getItem('timezone');
xxxxxxxxxx
var timedifference = new Date().getTimezoneOffset();
//This returns the difference from the clients timezone from UTC time. You can then play around with it as you like.