Skip to content

Instantly share code, notes, and snippets.

@carlbennett
Created April 23, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlbennett/e98d8dc6cf5951429aba966c7e1fe40e to your computer and use it in GitHub Desktop.
Save carlbennett/e98d8dc6cf5951429aba966c7e1fe40e to your computer and use it in GitHub Desktop.
Usage: ./dtconvert.php <timestamp> <to-timezone>
#!/usr/bin/env php
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
if (php_sapi_name() !== "cli") {
http_response_code(500);
exit("Must be ran by php-cli");
}
if ($argc < 3) {
exit(
"Usage: " . $argv[0] . " <timestamp> <to-timezone>" . PHP_EOL .
PHP_EOL .
" timestamp Any timestamp representation that is valid" . PHP_EOL .
" with the strtotime() function. Note that" . PHP_EOL .
" timestamps without a timezone are assumed" . PHP_EOL .
" to be in UTC, override this by appending" . PHP_EOL .
" a timezone to the timestamp." . PHP_EOL .
" to-timezone The timezone to convert timestamp to, see:" . PHP_EOL .
" <http://php.net/manual/en/timezones.php>" . PHP_EOL .
PHP_EOL
);
}
$timestamp = $argv[1];
$target = $argv[2];
$tz = new DateTimeZone("UTC");
$timestamp = new DateTime($timestamp, $tz);
$target = new DateTimeZone($target);
echo $timestamp->setTimezone($target)->format("c") . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment