Created
April 12, 2024 06:04
-
-
Save dewe/a3df56d854eaef71d7c584d7984ba0a1 to your computer and use it in GitHub Desktop.
epoch formatting, shell function (mac os / BSD)
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
# epoch format, use with arg or pipe; no argument -> echo current epoch | |
function epoch() { | |
fmt="+%Y-%m-%dT%H:%M:%S%z" | |
if [ -t 0 ] && [ -z "$1" ]; then | |
# no input, echo current epoch | |
date "+%s" | |
elif [[ -z "$1" ]]; then | |
# no arg, use piped value | |
xargs -I {} sh -c "date -r {} $fmt" | |
else | |
date -r $1 $fmt | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment