代码之家  ›  专栏  ›  技术社区  ›  justinhj

如何获取elisp时间指定的月份中的天数?

  •  2
  • justinhj  · 技术社区  · 16 年前

    在elisp中,我有一个时间(三个整数的形式),我可以使用解码时间得到月份。我想得到的是那个月(和那个年)的天数,使用elisp函数(而不是自己写)。

    即:

    (defun days-in-month-at-time(t)
        ; Figure out month and year with decode-time
        ; return number of days in that month   
    )
    
    2 回复  |  直到 16 年前
        1
  •  6
  •   viam0Zah    16 年前
    (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))))
    
        2
  •  1
  •   justinhj    16 年前

    似乎这更好,因为时区似乎不在所有最新的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))))
    
    推荐文章