Created
April 23, 2018 15:09
-
-
Save carlbennett/e98d8dc6cf5951429aba966c7e1fe40e to your computer and use it in GitHub Desktop.
Usage: ./dtconvert.php <timestamp> <to-timezone>
This file contains hidden or 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
#!/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