pixie123 pixie123 - 1 year ago 115
CSS Question

Detect Pacific timezone with Javascript

I want to do a if statment if the current time in pacific time is 11am. how can i do that? here is what i have right now:

var time = new Date().getHours();

if(time == 11) {
alert("this works");

but that only detects the user's time. how can i do pacific time only?

Answer Source

Combination of getTimezoneOffset() and PST (-7), currently Pacific Daylight Time!

var offset = new Date().getTimezoneOffset() / 60;
var localHour = new Date().getHours();
var PSTHour = localHour + offset - 7;
PSTHour = PSTHour > 0 ? PSTHour : PSTHour + 24;
console.log('PST hour: ' + PSTHour);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download