Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a simple keyboard macro to insert a comment with my name and a short timestamp. Is there an easy way to get a timestamp? Ideally I would be able to define it in my macro so that it uses a relatively short form like YY-MM-DD HH:MM.

I'd like it to be as common to emacs as possible, so I'd rather not resort to Org mode or other add-ons that might not be part of a standard installation. Here's basically what I have so far, what I need is what's between the angle braces:

(fset 'my-timestamp "[myname <YY-MM-DD HH:MM>]: ")
(global-set-key (kbd "C-c #") 'my-timestamp)
share|improve this question

Duh. I should have checked the emacs wiki first (http://www.emacswiki.org/emacs/InsertingTodaysDate). Here's a way they show that only relies on the emacs calendar. That's good enough for me.

  (defun timestamp ()
  (interactive)
  (insert (format-time-string "%Y-%m-%d %H:%M")))

After playing with several options from the emacs wiki link, I've revised this post to use the above, simpler function. Then I used the timestamp function while recording a macro I then put in my .emacs.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .