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 ) );
date_default_timezone_set(@date_default_timezone_get());
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?
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:
Please improve this answer if you have more insight.