Take a look at current_time()
.
Returns the blog’s current local time in the specified format. There are two named formats: ‘mysql’ for MySQL/MariaDB’s timestamp data type format (i.e. YYYY-MM-DD HH:MM:SS), and ‘timestamp’ for the Unix timestamp format (i.e. epoch). Other strings will be interpreted as PHP date formats (e.g. ‘Y-m-d’) since 3.9.0. The optional secondary parameter can be used to retrieve GMT time instead of the blog’s local time.
The local time returned is based on the timezone set on the blog’s General Settings page, which is UTC by default.
current_time( 'timestamp' )
should be used in lieu oftime()
to return the blog’s local time. In WordPress, PHP’stime()
will always return UTC and is the same as callingcurrent_time( 'timestamp', true )
.
You can also modify the TimeZone
of a date
.
$d = date( 'c', time() );
echo $d; // 2016-06-12T16:35:39+00:00
$t = new DateTime($d);
$t->setTimezone(new DateTimeZone( 'America/Los_Angeles' ));
echo "\tLOS\t" . $t->format( 'g:i:s A' ); // 9:35:39 AM
$t->setTimezone(new DateTimeZone( 'America/New_York' ));
echo "\tNYC\t" . $t->format( 'g:i:s A' ); // 12:35:39 PM
echo ( $t->format('G') < 9) ? ' Before 9AM' : ' After 9AM';