Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.