JS Timezone Hack

JavaScript

var setTimezoneOffset = function(date, offset) {
    // Shift the time so that UTC represents the "correct" time,
    // and then replace "getHours" with "getUTCHours".
    // This is only required because Daylight Savings in the local timezone
    // can interfere with the correct date formatting in the target timezone.
    date = new Date(date.getTime() + offset*60*1000);
    ['Minutes','Hours','Date','Month','FullYear'].forEach(function(value){
        date['get'+value] = date['getUTC'+value];
    });
    return date;
}




var d;
var fmt = '%I:%M:%S %p';





d = new Date();
console.log("Local:", d.format(fmt));

d = setTimezoneOffset(new Date(), 0*60)
console.debug("UTC:  ", d.format(fmt));

d = setTimezoneOffset(new Date(), -4*60)
console.debug("EDT:  ", d.format(fmt));

d = setTimezoneOffset(new Date(), -7*60)
console.log("PDT:  ", d.format(fmt));

d = setTimezoneOffset(new Date(), -10*60)
console.debug("HAST: ", d.format(fmt));