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()
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'));