Last active
October 8, 2015 21:19
-
-
Save billerickson/2648937 to your computer and use it in GitHub Desktop.
Display date using timezone in Settings > General
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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