Skip to content

Instantly share code, notes, and snippets.

@xream
Forked from lexrus/tc
Created March 26, 2012 10:26
Show Gist options
  • Save xream/2204343 to your computer and use it in GitHub Desktop.
Save xream/2204343 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