[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a command to insert today's date OR time (or both)?
From: |
Udyant Wig |
Subject: |
Re: a command to insert today's date OR time (or both)? |
Date: |
Sun, 09 Jan 2011 10:49:50 +0530 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
dkcombs@panix.com (David Combs) writes:
| I've looked in emacs' *info*, its list of commands, etc,
| and can find nothing.
|
| Sure would be nice to be to easily to insert the current
| date, time, or both.
|
| Thanks!
|
| David
Apart from what Pascal suggested, you could try these:
(defun insert-current-time ()
(interactive)
(destructuring-bind
(sec min hour day month year dow dst zone)
(decode-time)
(insert (format "%02d:%02d:%02d" hour min sec))))
(defun insert-current-date ()
(interactive)
(let ((days '((0 . Sunday)
(1 . Monday)
(2 . Tuesday)
(3 . Wednesday)
(4 . Thursday)
(5 . Friday)
(6 . Saturday)))
(months '((1 . Jan)
(2 . Feb)
(3 . Mar)
(4 . Apr)
(5 . May)
(6 . Jun)
(7 . Jul)
(8 . Aug)
(9 . Sep)
(10 . Oct)
(11 . Nov)
(12 . Dec))))
(destructuring-bind
(sec min hour day month year dow dst zone)
(decode-time)
(insert (format "%s, %d %s %d"
(rest (assoc dow days))
day
(rest (assoc month months))
year)))))
You could, of course, combine these as:
(defun insert-current-time-date ()
(interactive)
(insert-current-time)
(insert (format " "))
(insert-current-date))
Or whichever way you want them.
P.S. Suggested improvements gladly accepted.