-
-
Save hongster/cd462d11c491eef75c0b8dcd3768fa8d to your computer and use it in GitHub Desktop.
Command line app to convert to/from UNIX 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
#!/usr/bin/env php | |
<?php | |
if (count($argv) < 2) { | |
// Output current UNIX time if no argument specified | |
echo time()."\n"; | |
exit; | |
} | |
if (strtolower($argv[1]) == "help") { | |
$currentScript = basename($argv[0]); | |
echo <<<EOL | |
Example: | |
{$currentScript} 1624032013 | |
{$currentScript} "2000-12-25 23:59:59" | |
{$currentScript} yesterday | |
EOL; | |
} | |
elseif (is_numeric($argv[1])) { | |
// Convert from UNIX timestamp | |
echo date(DATE_RSS, $argv[1])."\n"; | |
} | |
else { | |
// Convert to UNIX timestamp | |
echo strtotime($argv[1])."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment