Skip to content

Instantly share code, notes, and snippets.

@davidlonjon
Last active December 15, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidlonjon/5235480 to your computer and use it in GitHub Desktop.
Save davidlonjon/5235480 to your computer and use it in GitHub Desktop.
JavaScript: Adjust Date Timezone
// Inspired from http://stackoverflow.com/questions/2771609/how-to-ignore-users-time-zone-and-force-date-use-specific-time-zone
function adjust_date_timezone(date, timezone_hours_offset, local_offset) {
date = set_default_arg(date, new Date());
timezone_hours_offset = !(timezone_hours_offset === null || typeof timezone_hours_offset === 'undefined') ? timezone_hours_offset: optools_settings.timezone_hours_offset;
local_offset = !(local_offset === null || typeof local_offset === 'undefined') ? local_offset: date.getTimezoneOffset() *60*1000;
return new Date(date.getTime() + local_offset + (timezone_hours_offset *60*60*1000));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment