Elisp: Print Date Time

By Xah Lee. Date: . Last updated: .

This page shows you how to print current date time in various formats.

See also: Elisp: Parse Date Time.

For a ready-to-use command, see Emacs: Insert Date Time πŸš€

Format yyyy-mm-dd

(format-time-string "%Y-%m-%d")
;; "2018-09-10"

ISO 8601 Format

ISO 8601 format, example 2018-09-10T17:39:31-07:00

 (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:

(format-time-string "%Y-%j") ; "2010-334" for 2010-11-30