Skip to content

Instantly share code, notes, and snippets.

@hongster
Last active February 8, 2023 02:35
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 hongster/cd462d11c491eef75c0b8dcd3768fa8d to your computer and use it in GitHub Desktop.
Save hongster/cd462d11c491eef75c0b8dcd3768fa8d to your computer and use it in GitHub Desktop.
Command line app to convert to/from UNIX time.
#!/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