all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Rogoff <david@therogoffs.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Insert date and Time
Date: Thu, 25 Feb 2010 11:20:29 -0800	[thread overview]
Message-ID: <4b86cd7c$0$30386$c32e2966@unlimited.newshosting.com> (raw)
In-Reply-To: 877hq1e5dx.fsf@galatea.lan.informatimago.com

On 2010-02-25 06:50:34 -0800, Pascal J. Bourguignon said:

> Tugello <kompy01@yahoo.it> writes:
> 
>> Hello,
>> good morning to all,I'm newbie with emacs
>> my question is about how to insert current date and time, using a short key
>> combination instead to write they completely .
>> someone ave any suggestion ?
>> thanks in advance
> 
> I type: C-u M-! date RET
> 
> A purely emacs lisp alternative would be:
> M-: (insert (current-time-string)) RET
> 
> 
> Of course, if you have to do it often, you can do:
> 
> (defun insert-timestamp ()
>   (interactive)
>   (insert (current-time-string)))
> 
> (global-set-key (kbd "<f8>") 'insert-timestamp)
> 
> so that you only have to type F8 to insert the timestamp.

Here's a couple of versions I use with some formatting and chioce of 
just date or date and time:

(defun insert-date ()
  "Insert current date at point, and newline if point is at beginning of line."
  (interactive)
  (if (prog1 (bolp)
        (let ((time (current-time-string)))
          (insert (substring time 4 11) (substring time 20 24)))
        )
      ;; insert newline if point was at beginning of line
      (insert ?\n))
  )

;; output looks like this:  Feb 25 2010

;; (global-set-key '[(meta f12)] 'insert-date)



(defun insert-date-and-time ()
  "Insert current date and time at point, and newline if point is at 
beginning of line."
  (interactive)
  (if (prog1 (bolp)
        (let ((time (current-time-string)))
          (insert (substring time 4 11) (substring time 20 24) 
(substring time 10 19) ) )
        )
      ;; insert newline if point was at beginning of line
      (insert ?\n))
  )

(global-set-key '[A-home] 'insert-date-and-time)

;; output looks like this:  Feb 25 2010 11:05:43



  reply	other threads:[~2010-02-25 19:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1861.1267108056.14305.help-gnu-emacs@gnu.org>
2010-02-25 14:50 ` Insert date and Time Pascal J. Bourguignon
2010-02-25 19:20   ` David Rogoff [this message]
2010-02-25 22:23 ` Tim X
2010-02-25 22:26 ` B. T. Raven
2010-02-25  8:29 Tugello
2010-02-25 14:41 ` Tim Visher
2010-02-25 14:49 ` Kevin Rodgers
2010-02-25 22:52 ` Drew Adams
2010-02-26  6:26   ` Kevin Rodgers
2010-02-26 15:02     ` Drew Adams
     [not found] ` <mailman.1862.1267108938.14305.help-gnu-emacs@gnu.org>
2010-03-02  8:40   ` Uwe Siart
2010-03-02 10:36     ` Andreas Röhler
     [not found]     ` <mailman.2134.1267526036.14305.help-gnu-emacs@gnu.org>
2010-03-02 13:25       ` Uwe Siart
2010-03-05 15:06       ` Jim Diamond

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='4b86cd7c$0$30386$c32e2966@unlimited.newshosting.com' \
    --to=david@therogoffs.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.