Display date using timezone from Settings > General

<?php
/**
* Display date using timezone in Settings > General
*
* You might want to display or query based on the current day/time.
* The date() function is great for that, EXCEPT it uses the server's
* timezone, which in my experience is typically GMT (six hours ahead
* of me here in Texas).
*
* WordPress lets you select a timezone in Settings > General, so let's
* use that instead!
*
* For information on formatting date/time (the first parameter), see
* http://codex.wordpress.org/Formatting_Date_and_Time
*/
$date = date( 'F j, Y g:i a', current_time('timestamp') );
/**
* Alter a unix timestamp based on server's timezone
*
*/
$date = get_post_meta( get_the_ID(), 'ea_share_count_datetime', true );
$date = $date + ( get_option( 'gmt_offset' ) * 3600 );
echo date( 'F j, Y g:ia', $date );
view raw gistfile1.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk