Skip to content

Instantly share code, notes, and snippets.

@kjbenk
Last active August 3, 2017 20:18
Show Gist options
  • Save kjbenk/bc9e42f6cb6246eebdd0b2f8529da8ae to your computer and use it in GitHub Desktop.
Save kjbenk/bc9e42f6cb6246eebdd0b2f8529da8ae to your computer and use it in GitHub Desktop.
WordPress: Get local date
<?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