Skip to content

Instantly share code, notes, and snippets.

Created Jul 31, 2017
What would you like to do?
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