Elisp: Print Date Time
Format yyyy-mm-dd
(format-time-string "%Y-%m-%d") ;; "2018-09-10"
Common Computer Format yyyymmdd_hhmmss
(format-time-string "%Y%m%d_%H%M%S") ;; "20241002_105213"
ISO 8601 Format
ISO 8601 format, example 2018-09-10T17:39:31-07:00
(concat (format-time-string "%Y-%m-%dT%T") ((lambda (x) (concat (substring x 0 3) ":" (substring x 3 5))) (format-time-string "%z"))) ;; sample output ;; 2018-09-10T17:39:31-07:00
Unix Time Format
(number of seconds since .)
;; unix time (format-time-string "%s") ; "1291104066"
Names for Month and Week
;; full month name (format-time-string "%B") ; "November" ;; abbreviated month name (format-time-string "%b") ; "Nov"
;; full week name (format-time-string "%A") ; "Tuesday" ;; abbreviated week name (format-time-string "%a") ; "Tue"
Ordinal Date Format
format-time-string
also supports ordinal date format. For example:
- “2010 January 1st” = “2010-001”
- “2010 December 31” = “2010-365”
(format-time-string "%Y-%j") ; "2010-334" for 2010-11-30