Skip to content

Instantly share code, notes, and snippets.

@tst2005
Created June 27, 2016 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tst2005/aeef2d0bad6ef1904c06fb1a8b4589b5 to your computer and use it in GitHub Desktop.
Save tst2005/aeef2d0bad6ef1904c06fb1a8b4589b5 to your computer and use it in GitHub Desktop.
# https://en.wikipedia.org/wiki/ISO_8601
date_to_iso8601() {
date ${1:+-d "$1"} -u +'%Y%m%dT%H%M%SZ'
}
iso8601_to_date() {
local yyyymmdd="${1%%T*}"
local hhmmss="${1#*T}"
hhmmss="${hhmmss%Z*}"
local mmss="${hhmmss#??}"
shift
date -d "${yyyymmdd} ${hhmmss%%????}:${mmss%??}:${mmss#??} +0000" "$@"
}
iso8601_to_date "$(date_to_iso8601 "$(iso8601_to_date "$(date_to_iso8601)")")" -u
date -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment