Skip to content

Instantly share code, notes, and snippets.

@takehiko
Created February 17, 2021 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save takehiko/306021460b21f5d1520c32293cd831e0 to your computer and use it in GitHub Desktop.
Save takehiko/306021460b21f5d1520c32293cd831e0 to your computer and use it in GitHub Desktop.
Functions for inserting a timestamp in several different ways on Emacs
;; M-x insert-timestamp-default (またはM-x its)で Wed Feb 17 22:18:46 2021
;; M-x insert-timestamp-htmlcomment (またはM-x itsh)で <!-- 2021-02-17 22:18:52 +09:00 --> (と改行)
;; M-x insert-timestamp-unixtime (またはM-x itsu)で 1613567937
;; M-x insert-timestamp-iso (またはM-x itsi)で 2021-02-17T22:19:01+09:00
(defun insert-timestamp-default ()
"Insert the current timestamp"
(interactive)
(insert (current-time-string)))
(defalias 'its 'insert-timestamp-default)
(defun insert-timestamp-htmlcomment ()
"Insert the current timestamp (HTML comment)"
(interactive)
(insert
(concat
"<!-- "
(format-time-string "%Y-%m-%d %T ")
((lambda (x) (concat (substring x 0 3) ":" (substring x 3 5)))
(format-time-string "%z"))
" -->\n")))
(defalias 'itsh 'insert-timestamp-htmlcomment)
(defun insert-timestamp-unixtime ()
"Insert the current Unix time"
(interactive)
(let ((time (current-time)))
(let ((time1 (car time))
(time2 (car (cdr time))))
(insert (format "%d" (+ (* 65536 time1) time2))))))
(defalias 'itsu 'insert-timestamp-unixtime)
(defun insert-timestamp-iso ()
"Insert the current timestamp (ISO 8601 format)"
(interactive)
(insert
(concat
(format-time-string "%Y-%m-%dT%T")
((lambda (x) (concat (substring x 0 3) ":" (substring x 3 5)))
(format-time-string "%z")))))
(defalias 'itsi 'insert-timestamp-iso)
(defalias 'itsiso 'insert-timestamp-iso)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment