Skip to content

Instantly share code, notes, and snippets.

@hongster
Created Jul 19, 2021
Embed
What would you like to do?
Command line app to convert to/from UNIX time.
#!/usr/bin/env php
<?php
if (count($argv) < 2) {
// Output current UNIX time if not 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