help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Diary insert date formatting


From: Xah Lee
Subject: Re: Diary insert date formatting
Date: Sat, 8 Aug 2009 20:55:10 -0700 (PDT)
User-agent: G2/1.0

On Aug 8, 12:46 pm, rpd <rich...@dickinson350.freeserve.co.uk> wrote:
> Hi
> Currently when I insert a diary date it is entered in this format:
> Jul 31, 2009
>
> Can I change this to include the abbreviated day as well e.g:
> Fri Jul 31, 2009 ?

use format-time-string.


call describe-function on the function.

here's some example how i use it.

(defun insert-date () "Insert current date." (interactive)
  (insert (format-time-string "%Y-%m-%d"))
)
(put 'insert-date 'delete-selection t)

(defun insert-date-time ()
  "Insert current date-time string."
  (interactive)
  (insert
   (concat
    (format-time-string "%Y-%m-%dT%T")
    ((lambda (x) (concat (substring x 0 3) ":" (substring x 3 5)))
     (format-time-string "%z")))))

(defun fix-timestamp-string (timestr)
  "Returns yyyy-mm-dd format of TIMESTR.

For example: “Nov. 28, 1994” ⇒ “1994-11-28”.

The result only contains year, month, date.
Any century, “day of week”, or time info are discarded."
  (let (li year month date yyyy mm dd)
    (setq timestr (replace-regexp-in-string "January " "Jan. "
timestr))
    (setq timestr (replace-regexp-in-string "February " "Feb. "
timestr))
    (setq timestr (replace-regexp-in-string "March " "Mar. " timestr))
    (setq timestr (replace-regexp-in-string "April " "Apr. " timestr))
    (setq timestr (replace-regexp-in-string "May " "May. " timestr))
    (setq timestr (replace-regexp-in-string "June " "Jun. " timestr))
    (setq timestr (replace-regexp-in-string "July " "Jul. " timestr))
    (setq timestr (replace-regexp-in-string "August " "Aug. "
timestr))
    (setq timestr (replace-regexp-in-string "September " "Sep. "
timestr))
    (setq timestr (replace-regexp-in-string "October " "Oct. "
timestr))
    (setq timestr (replace-regexp-in-string "November " "Nov. "
timestr))
    (setq timestr (replace-regexp-in-string "December " "Dec. "
timestr))

    (setq li (parse-time-string timestr))
    (setq year (nth 5 li))
    (setq month (nth 4 li))
    (setq date (nth 3 li))

    (setq yyyy (number-to-string year))

    (setq mm
          (if (< month 10)
              (concat "0" (number-to-string month))
            (number-to-string month)))

    (setq dd
          (if (< date 10)
              (concat "0" (number-to-string date))
            (number-to-string date)))

    (concat yyyy "-" mm "-" dd)))

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]