Skip to content

Instantly share code, notes, and snippets.

@nicdoye
Created July 31, 2017 10:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nicdoye/6b9d70cf4b997a524b77740f241374d4 to your computer and use it in GitHub Desktop.
macOS ISO8601 dates
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