Last active
August 3, 2017 20:18
-
-
Save kjbenk/bc9e42f6cb6246eebdd0b2f8529da8ae to your computer and use it in GitHub Desktop.
WordPress: Get local date
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 | |
/** | |
* Get the local date with a specific format. | |
* | |
* @param string $timestamp UNIX timestamp. | |
* @param string $format Date format. | |
* @return string Local date string. | |
*/ | |
function get_local_date( $timestamp, $format = null ) { | |
if ( empty( $format ) ) { | |
$format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); | |
} | |
// Localize timestamp. | |
$timestamp += get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; | |
return date( $format, $timestamp ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment