# Add the following to your ~/.bashrc or ~/.zshrc
# prints current epoch in milliseconds
# >epoch
# >1616738907653
alias epoch='python -c "from time import time; print int(round(time() * 1000))"'
# prints current epoch in human readable date in UTC timezone
# >utc
# >2021-03-26 06:08:27.653000
alias utc='python -c "from time import time; import datetime; print datetime.datetime.utcfromtimestamp(int(round(time() * 1000))/ 1000.0)"'
# prints specified epoch in human readable date in System timezone
# >epoch_to_date 1616738907653
# >2021-03-26 11:38:27.653000
epoch_to_date() {
python -c "import datetime; print datetime.datetime.fromtimestamp($1 / 1000.0)"
}
# prints current epoch in human readable date in UTC timezone
# >epoch_to_utc 1616738907653
# >2021-03-26 06:08:27.653000
epoch_to_utc() {
python -c "import datetime; print datetime.datetime.utcfromtimestamp($1 / 1000.0)"
}
# Python 3 version, courtesy https://twitter.com/arion_miles
# prints current epoch in milliseconds
# >epoch
# >1616738907653
alias epoch='python3 -c "from time import time; print(round(time() * 1000))"'
# prints current epoch in human readable date in UTC timezone
# >utc
# >2021-03-26 06:08:27.653000
alias utc='python3 -c "from time import time; import datetime; print(datetime.datetime.utcfromtimestamp(round(time() * 1000)/ 1000.0))"'
# prints specified epoch in human readable date in System timezone
# >epoch_to_date 1616738907653
# >2021-03-26 11:38:27.653000
epoch_to_date() {
python3 -c "import datetime; print(datetime.datetime.fromtimestamp($1 / 1000.0))"
}
# prints current epoch in human readable date in UTC timezone
# >epoch_to_utc 1616738907653
# >2021-03-26 06:08:27.653000
epoch_to_utc() {
python3 -c "import datetime; print(datetime.datetime.utcfromtimestamp($1 / 1000.0))"
}