Skip to content

Instantly share code, notes, and snippets.

@swrogers
Forked from takehiko/insert-timestamp.el
Created March 16, 2024 21:57
Show Gist options
  • Select an option

  • Save swrogers/d8b93f873b490034610d79c497024508 to your computer and use it in GitHub Desktop.

Select an option

Save swrogers/d8b93f873b490034610d79c497024508 to your computer and use it in GitHub Desktop.

Revisions

  1. @takehiko takehiko created this gist Feb 17, 2021.
    42 changes: 42 additions & 0 deletions insert-timestamp.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    ;; 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)