Skip to content

Instantly share code, notes, and snippets.

@gongo
Last active December 17, 2015 16:09
Show Gist options
  • Save gongo/5636492 to your computer and use it in GitHub Desktop.
Save gongo/5636492 to your computer and use it in GitHub Desktop.
Parse ISO8601 (Zulu) string
(defun gongo:read-datetime ()
(unless (re-search-forward "\\([0-9]\\{4\\}\\)-\\(0[1-9]\\|1[0-2]\\)-\\(0[1-9]\\|[1-2][0-9]\\|3[0-1]\\)T\\([0-1][0-9]\\|2[0-4]\\):\\([0-5][0-9]\\):\\([0-5][0-9]\\)Z" nil t)
(message "error"))
(let ((seconds (string-to-number (match-string-no-properties 6)))
(minutes (string-to-number (match-string-no-properties 5)))
(hour (string-to-number (match-string-no-properties 4)))
(day (string-to-number (match-string-no-properties 3)))
(month (string-to-number (match-string-no-properties 2)))
(year (string-to-number (match-string-no-properties 1))))
(list seconds minutes hour day month year)))
(let (datetime)
(setq datetime (with-temp-buffer
(insert "1979-05-27T07:32:00Z")
(goto-char (point-min))
(gongo:read-datetime)))
(format-time-string "%Y-%m-%d [%H:%M:%S]" (apply 'encode-time datetime)))
;; => "1979-05-27 [07:32:00]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment