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

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

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

(info "(elisp) Time Parsing")

(info "(elisp) Time of Day")

Datetime

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


ELisp

Basics

Basic Functions

Writing Command

Writing Script

Lisp Data Structure

Lisp Symbol

Elisp Misc