Skip to content

Instantly share code, notes, and snippets.

@pandauxstudio
Created February 19, 2014 21:14
Show Gist options
  • Save pandauxstudio/9101728 to your computer and use it in GitHub Desktop.
Save pandauxstudio/9101728 to your computer and use it in GitHub Desktop.
Timezone-Adjusted Timestamp
// Source: http://stackoverflow.com/questions/2834353/php-how-do-i-convert-a-server-timestamp-to-the-users-timezone
$timestamp = time();
echo 'Unix timestamp: ' . $timestamp;
$dt = DateTime::createFromFormat('U', $timestamp);
$dt->setTimeZone(new DateTimeZone($timezone));
$adjusted_timestamp = $dt->format('U') + $dt->getOffset();
echo ' Timestamp adjusted for: ' . $timezone . $adjusted_timestamp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment