Created
July 3, 2012 17:49
-
-
Save nagakputtagunta/3041340 to your computer and use it in GitHub Desktop.
A Shell script to convert Unix Time to Human Readable Format and Vice Versa
This file contains hidden or 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
if echo {query} | grep -Gq '^[0-9]\{1,\}$' | |
then | |
# Epoch to Human Readable Time Conversion | |
date -r {query} -u "+%Y-%m-%d %H:%M:%S %Z" | |
elif echo {query} | grep -Gq '^[0-9]\{4\}-[0-9]\{1,2\}-[0-9]\{1,2\} [0-9]\{1,2\}:[0-9]\{1,2\}:[0-9]\{1,2\}$' | |
then | |
# Human Readable to Epoch Time Conversion | |
date -j -u -f "%Y-%m-%d %H:%M:%S" "{query}" "+%s" | |
else | |
# Invalid Input | |
echo "Use %Y-%m-%d %H:%M:%S" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added support to display Timezone when converting from epoch time