2009-08-17 5 views
1

elispでは(3つの整数の形で)時間があり、デコード時を使って月を得ることができます。私が得たいのは、その月と年の日数で、自分で書くのではなく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 –

+0

パーフェクト、感謝を! – justinhj

+0

私の作業マシンにtimezone-last-day-of-monthが存在しないemacsのWindowsビルド23.1.1削除されたのか、それ以降に追加されたのだろうか? – justinhj

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で私にとってはうまくいきません。(月の日数(現時点)) –

+0

私はあなたが必要と思います(カレンダーが必要です)。 – justinhj

関連する問題