Created
July 31, 2017 10:43
-
-
Save nicdoye/6b9d70cf4b997a524b77740f241374d4 to your computer and use it in GitHub Desktop.
macOS ISO8601 dates
This file contains 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
my_date () { | |
local date_cmd | |
local date | |
# Check if GNU date installed as gdate | |
: type gdate 2> /dev/null | |
[ $? == 0 ] && date_cmd=gdate || date_cmd=date | |
# Attempt GNU date - date will be unset if this fails | |
date=$(${date_cmd} --iso-8601=second 2> /dev/null) | |
# Use date if unset. This will hopefully be BSD date | |
echo ${date:=$(local x=$(date '+%FT%T%z'); echo ${x/%00/}):00 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment