This question already has an answer here:

This code does not work correctly and returns time using timezone from computer and ignoring timezone stored in WordPress options:

date_default_timezone_set( get_option( 'timezone_string' ) );
$hours = date( 'H', strtotime( $timestamp ) );

WordPress saves timezone in options section but 'timezone_string' option in wp_options table is empty. Also the code generates warnings.

How to get date using timezone saved in options correctly?

Where does WordPress store an Timezone which can be edited in options section?

marked as duplicate by Chip Bennett, s_ha_dum Feb 10 '14 at 17:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    You should use current_time('mysql') to get the current date based on wordpress timezone settings. The return value would be 'Y-m-d H:i:s' formatted time. This is used to get the time, not the timezone name or GMT difference. – Shazzad Feb 10 '14 at 15:05
  • @Shazzad Where does WordPress store an Timezone which can be edited in options section? – webvitaly Feb 10 '14 at 16:19

I use this:

$mytheme_timezone = get_option('timezone_string'); date_default_timezone_set($mytheme_timezone);

in my themes functions.php. For me this has worked without any warnings.

I've also tested whether my script is in different timezone than php.ini:

 if (strcmp($mytheme_timezone, ini_get('date.timezone'))){
 echo 'Script timezone differs from ini-set timezone.';
else {
 echo 'Script timezone and ini-set timezone match.';

Please improve this answer if you have more insight.

Not the answer you're looking for? Browse other questions tagged or ask your own question.