Ray*_*ega 70 emacs datetime timestamp text-editor
我可以使用Emacs中的哪些命令将当前日期和时间插入文件的文本缓冲区?
(例如,记事本中的等价物只是按下F5,这是记事本唯一有用的功能!)
小智 130
C-u M-! date
Run Code Online (Sandbox Code Playgroud)
CMS*_*CMS 37
放入.emacs文件:
;; ====================
;; insert date and time
(defvar current-date-time-format "%a %b %d %H:%M:%S %Z %Y"
"Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")
(defvar current-time-format "%a %H:%M:%S"
"Format of date to insert with `insert-current-time' func.
Note the weekly scope of the command's precision.")
(defun insert-current-date-time ()
"insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
(interactive)
(insert "==========\n")
; (insert (let () (comment-start)))
(insert (format-time-string current-date-time-format (current-time)))
(insert "\n")
)
(defun insert-current-time ()
"insert the current time (1-week scope) into the current buffer."
(interactive)
(insert (format-time-string current-time-format (current-time)))
(insert "\n")
)
(global-set-key "\C-c\C-d" 'insert-current-date-time)
(global-set-key "\C-c\C-t" 'insert-current-time)
Run Code Online (Sandbox Code Playgroud)
Mic*_*nis 29
我用过这些简短的片段:
(defun now ()
"Insert string for the current time formatted like '2:34 PM'."
(interactive) ; permit invocation in minibuffer
(insert (format-time-string "%D %-I:%M %p")))
(defun today ()
"Insert string for today's date nicely formatted in American style,
e.g. Sunday, September 17, 2000."
(interactive) ; permit invocation in minibuffer
(insert (format-time-string "%A, %B %e, %Y")))
Run Code Online (Sandbox Code Playgroud)
他们最初来自journal.el
tan*_*nfa 17
对于插入日期:
M-x org-time-stamp
Run Code Online (Sandbox Code Playgroud)
对于插入日期时间:
C-u M-x org-time-stamp
Run Code Online (Sandbox Code Playgroud)
您可以绑定此命令的全局键.
org-mode该方法非常用户友好,您可以从日历中选择任何日期.
这是我刚才写的一个包,它可以满足您的要求.
http://github.com/rmm5t/insert-time.el/tree/master/insert-time.el
(require 'insert-time)
(define-key global-map [(control c)(d)] 'insert-date-time)
(define-key global-map [(control c)(control v)(d)] 'insert-personal-time-stamp)
Run Code Online (Sandbox Code Playgroud)