Last active
September 20, 2017 23:26
-
-
Save wpscholar/5900473 to your computer and use it in GitHub Desktop.
Properly fetch the local date / time in WordPress based on a Unix timestamp.
This file contains hidden or 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 | |
/** | |
* Fetch the local date/time in WordPress based on a Unix timestamp. | |
* | |
* @param int $timestamp | |
* @param string $format | |
* @return string | |
*/ | |
function get_wp_local_date_time( $timestamp, $format = '' ) { | |
$format = !empty( $format ) ? $format: get_option('date_format') . ' ' . get_option('time_format'); | |
if( ! $timezone = get_option('timezone_string') ) { | |
$timezone = date_default_timezone_get(); | |
} | |
date_default_timezone_set( $timezone ); | |
return date_i18n( $format, $timestamp ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment