如何转换(日月)到(月日)

时间:2013-10-26 18:09:09

标签: emacs elisp

我在Wanderlust的电子邮件中有一个标题如下:

Date:  Wed, 23 Oct 2013 12:18:15 -0700

我想修改print-to-pdf函数的开头,以便它在当前缓冲区中搜索它找到的第一个日期(通常是缓冲区的第一行)并将其转换为建议的{{1}看起来像这样:

pdf-file-name

我的10_23_2013.pdf 函数的开头是这样的:

print-to-pdf

有人能想出一种方法来搜索日期并将其转换为建议的(defun print-to-pdf (pdf-file-name) "Print the current buffer to the given file." (interactive (list (ns-read-file-name "Write PDF file: " "/Users/HOME/.0.data/" nil ".pdf"))) (cond ( (not (equal pdf-file-name nil)) *** 吗?


编辑:以下是我通过点击Wanderlust代码找到的一些日期字符串函数:

pdf-file-name

1 个答案:

答案 0 :(得分:2)

这是功能。 如果你能找到一种方法来提取Wed, 23 Oct 2013 12:18:15 -0700,它就会产生 10_23_2013.pdf

(defun transform-date (s &optional shift)
  (let ((time (apply 'encode-time
                     (org-read-date-analyze
                      s nil
                      (decode-time (current-time))))))
    (when shift
      (setq time (time-add time (days-to-time shift))))
    (format-time-string "%m_%d_%Y.pdf" time)))

以下是日期的简单发现者:

(defun find-and-transform ()
  (goto-char (point-min))
  (when (re-search-forward "Date: \\([^:]*?\\)[0-9]+:")
    (transform-date
     (match-string-no-properties 1))))