Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active October 8, 2015 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/2648937 to your computer and use it in GitHub Desktop.
Save billerickson/2648937 to your computer and use it in GitHub Desktop.
Display date using timezone in 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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment