Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/gist:2648937
Last active Oct 8, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.