I have a countdown clock that is set to countdown to 8am on January 1, 2014.
I am using the following code to set the date:
var futureDate = new Date(2014, 0, 1, 8, 0, 0, 0);
This works but I would like to take it a step further and set it to a specific timezone. In my case UTC -7.
I have read this answer which says to use:
new Date(Date.UTC(year, month, day, hour, minute, second))
but what I am confused about is how I set the timezone to be UTC -7 and what I read online only leaves me more confused.
Can someone explain how Date.UTC
works and how do I set a timezone so my countdown clock is counting down based on the specified timezone?
Note: Any answer must be client side only code.
Date.UTC creates a timevalue for the provided year, month, date, etc. without any offset. So if the client machine is set for, say, UTC +05:00 then:
will create a date equivalent to noon on 30 December 2013 at Greenwich. Alerting the date will print a local time (assuming +5:00) equivalent to 2013-12-30T17:00:00+05:00.
You can't set the timezone, however you can use UTC values to create a date object, adjust the hours and minutes for the offset, then use the UTC methods to get the date and time components for the countdown.
e.g.
If non–UTC methods are used, the local offset will affect the result.