all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Udyant Wig <udyantw@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: a command to insert today's date OR time (or both)?
Date: Sun, 09 Jan 2011 10:49:50 +0530	[thread overview]
Message-ID: <87ei8mejrd.fsf@panda.goosenet.in> (raw)
In-Reply-To: igb1ak$djt$1@panix3.panix.com

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.


  parent reply	other threads:[~2011-01-09  5:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-09  1:00 a command to insert today's date OR time (or both)? David Combs
2011-01-09  3:30 ` Pascal J. Bourguignon
2011-01-09 12:06   ` Gregor Zattler
2011-01-09  5:19 ` Udyant Wig [this message]
2011-01-09  5:30   ` Udyant Wig
2011-01-09 14:23   ` Drew Adams
2011-01-09 14:32 ` Drew Adams
2011-01-09 14:42   ` Le Wang
     [not found]   ` <mailman.18.1294584142.18702.help-gnu-emacs@gnu.org>
2011-01-21  1:33     ` David Combs
2011-01-21 11:36       ` ken

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ei8mejrd.fsf@panda.goosenet.in \
    --to=udyantw@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.