Emacs: Insert Date Time
Here's a command to insert current date/time.
(require 'ido) ; part of emacs
(defun xah-insert-date () "Insert current date time. Insert date in this format: yyyy-mm-dd. If `universal-argument' is called first, prompt for a format to use. If there's text selection, delete it first. URL `http://xahlee.info/emacs/emacs/elisp_insert-date-time.html' version 2020-09-07" (interactive) (let (($style (if current-prefix-arg (string-to-number (substring (ido-completing-read "Style:" '( "1 → 2018-04-12 Thursday" "2 → 20180412224611" "3 → 2018-04-12T22:46:11-07:00" "4 → 2018-04-12 22:46:11-07:00" "5 → Thursday, April 12, 2018" "6 → Thu, Apr 12, 2018" "7 → April 12, 2018" "8 → Apr 12, 2018" )) 0 1)) 0 ))) (when (use-region-p) (delete-region (region-beginning) (region-end))) (insert (cond ((= $style 0) ;; "2016-10-10" (format-time-string "%Y-%m-%d")) ((= $style 1) ;; "2018-04-12 Thursday" (format-time-string "%Y-%m-%d %A")) ((= $style 2) ;; "20180412224015" (replace-regexp-in-string ":" "" (format-time-string "%Y%m%d%T"))) ((= $style 3) (concat (format-time-string "%Y-%m-%dT%T") (funcall (lambda ($x) (format "%s:%s" (substring $x 0 3) (substring $x 3 5))) (format-time-string "%z"))) ;; "2018-04-12T22:45:26-07:00" ) ((= $style 4) (concat (format-time-string "%Y-%m-%d %T") (funcall (lambda ($x) (format "%s:%s" (substring $x 0 3) (substring $x 3 5))) (format-time-string "%z"))) ;; "2018-04-12 22:46:11-07:00" ) ((= $style 5) (format-time-string "%A, %B %d, %Y") ;; "Thursday, April 12, 2018" ) ((= $style 6) (format-time-string "%a, %b %d, %Y") ;; "Thu, Apr 12, 2018" ) ((= $style 7) (format-time-string "%B %d, %Y") ;; "April 12, 2018" ) ((= $style 8) (format-time-string "%b %d, %Y") ;; "Apr 12, 2018" ) (t (format-time-string "%Y-%m-%d"))))))