Z31o_0
5/31/2019 - 3:27 AM

Datetime by timezone

Get date time of special timezone

function getSpecialDataTime(offset) {
    // create Date object for current location
    var d = new Date();

    // convert to msec
    // subtract local time zone offset
    // get UTC time in msec
    var utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    // create new Date object for different city
    // using supplied offset
    var nd = new Date(utc + (3600000*offset));

    // return time as a string
    return nd.toLocaleString();
}

// Usage
console.log(getSpecialDataTime('+5.5'));
function getSpecialDataTime(timezoneName, format) {
	var options = {
	    timeZone: timezoneName,
	    year: 'numeric', month: 'numeric', day: 'numeric',
	    hour: 'numeric', minute: 'numeric', second: 'numeric',
	};
	var formatter = new Intl.DateTimeFormat(format, options);
	return formatter.format(new Date());
}

// Usage
console.log(getSpecialDataTime('Europe/London', 'en-US'));