PHP - Set DateTimeZone of DateTime

// http://php.net/manual/en/function.date.php $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';

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.