Last active
December 17, 2015 16:09
-
-
Save gongo/5636492 to your computer and use it in GitHub Desktop.
Parse ISO8601 (Zulu) string
This file contains hidden or 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
(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