Skip to content

Instantly share code, notes, and snippets.

@lexrus
Created March 15, 2012 03:43
Show Gist options
  • Save lexrus/2041751 to your computer and use it in GitHub Desktop.
Save lexrus/2041751 to your computer and use it in GitHub Desktop.
Epoch / Unix Timestamp Converter
#!/bin/bash
# sudo chmod +x tc;sudo mv tc /usr/bin
if [[ -z "$1" ]]
then
printf %s "\
Nifty Timestamp Convertor by Lex Tang
tc 2012/12/12
tc 1355283413
"
exit
fi
if [[ "$1" == *"/"* ]]
then
s=$(date -j -f "%Y/%m/%d" "$1" "+%s")
else
s=$(ruby -e "puts Time.at($1).strftime('%Y-%m-%d %H:%M:%S %z')")
fi
echo $s
echo $s | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment