Created
February 21, 2017 18:40
-
-
Save rockschtar/896b192a1b0e525d3f67116cda9b3290 to your computer and use it in GitHub Desktop.
Convert UNIX Timestamp to WordPress Local Time
This file contains 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
function convertTimestampToWPDateTime(int $timestamp) : \DateTime { | |
$tz = get_option('timezone_string'); | |
if (!$tz) { | |
$offset = get_option('gmt_offset'); | |
$tz = timezone_name_from_abbr('', $offset * 3600, false); | |
} | |
$datetime = new \DateTime('@' . $timestamp); | |
$datetime->setTimezone(new \DateTimeZone($tz)); | |
return $datetime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment