Last active
December 15, 2015 08:59
-
-
Save davidlonjon/5235480 to your computer and use it in GitHub Desktop.
JavaScript: Adjust Date Timezone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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