Skip to content

Instantly share code, notes, and snippets.

@sumitpore
Created September 17, 2020 08:06
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 sumitpore/d9c6434e16088f558149d383c02e0541 to your computer and use it in GitHub Desktop.
Save sumitpore/d9c6434e16088f558149d383c02e0541 to your computer and use it in GitHub Desktop.
WordPress derive Timezone from gmt_offset option
function wp_timezone_object_from_gmt_offset() {
$min = 60 * get_option('gmt_offset');
$sign = $min < 0 ? "-" : "+";
$absmin = abs($min);
$tz = sprintf("%s%02d%02d", $sign, $absmin/60, $absmin%60);
return new DateTimeZone( $tz );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment