Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active September 20, 2017 23:26
Show Gist options
  • Save wpscholar/5900473 to your computer and use it in GitHub Desktop.
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.
<?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