How to get date using timezone saved in options? [duplicate]

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.

error code: 523