2009-08-17 60 views
1

在elisp中,我有一段時間(三個整數形式),並且我可以使用解碼時間獲取月份。我想要得到的是使用elisp函數(而不是自己寫)的月份(和年份)中的天數。如何獲取elisp時間指定月份的天數?

即:

(defun days-in-month-at-time(t) 
    ; Figure out month and year with decode-time 
    ; return number of days in that month 
) 

回答

5
(require 'timezone) 

(defun days-in-month-at-time (time) 
    "Return number of days in month at TIME." 
    (let ((datetime (decode-time time))) 
    (timezone-last-day-of-month (nth 4 datetime) (nth 5 datetime)))) 
+0

另請參閱相關的SO問題:http://stackoverflow.com/questions/753248/insert-whole-month-of-dates-in-emacs-lisp – 2009-08-17 13:04:10

+0

完美,謝謝! – justinhj 2009-08-17 14:08:03

+0

我的工作機器上不存在timezone-last-day-of-month Windows版本的emacs 23.1.1我不知道它是否已被刪除或在此之後添加? – justinhj 2009-08-26 20:14:09

0

看起來這是更好,因爲時區似乎並沒有在所有emacs的最近版本 編輯:對不起,你只需要需要時區,或根據日曆關於你是否使用這個或其他答案。

(defun days-in-month-at-time (time) 
    "Return number of days in month at TIME." 
    (let ((datetime (decode-time time))) 
    (calendar-last-day-of-month (nth 4 datetime) (nth 5 datetime)))) 
+0

這在Mac上的emacs 22.1.1中不適用於我:(日期時間(當前時間)) – 2009-10-08 03:49:54

+0

我認爲您首先需要(需要'日曆')。 – justinhj 2009-10-08 18:19:26

相關問題