Skip to content

Instantly share code, notes, and snippets.

@abelcallejo
Last active May 8, 2020 01:55
Show Gist options
  • Save abelcallejo/1b01a20211e7f63287db995aceaebe89 to your computer and use it in GitHub Desktop.
Save abelcallejo/1b01a20211e7f63287db995aceaebe89 to your computer and use it in GitHub Desktop.
Getting the timezone offsets

Getting the timezone offsets

The difference between the generated time using:

  1. the Default timezone setting; versus
  2. the UTC timezone

JavaScript

new Date().getTimezoneOffset();

WordPress

get_option('gmt_offset');

PHP

/** PHP core **/


/** PHP via shell **/
ob_start();
system('date +"%z"');
$offset = ob_get_contents();
ob_end_clean();
echo $offset; // +0800

MySQL

SELECT TIMEDIFF(NOW(),CONVERT_TZ(NOW(),@@session.time_zone,'+00:00'))

Linux/Unix

date +"%z"
# +0800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment