Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rockschtar/896b192a1b0e525d3f67116cda9b3290 to your computer and use it in GitHub Desktop.
Save rockschtar/896b192a1b0e525d3f67116cda9b3290 to your computer and use it in GitHub Desktop.
Convert UNIX Timestamp to WordPress Local Time
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