gpt4 book ai didi

datetime - 如何使用Emacs Lisp在Emacs中添加日期?

转载 作者:行者123 更新时间:2023-12-03 18:25:08 26 4
gpt4 key购买 nike

我想使用Emacs Lisp进行数学运算,例如在日期和时间上进行加和减。

最佳答案

简短的答案是:阅读elisp信息手册的System Interface section。更具体地说,时间部分:

  • Time of day
  • Time conversion
  • Time parsing
  • Time calculations

  • 更长的答案:

    Emacs可以将时间值用作字符串,浮点数或两个或三个整数的元组。例如。在 *scratch*缓冲区中调用一些函数:
    (current-time)
    (19689 59702 984160)
    (current-time-string)
    "Sun Nov 21 20:54:22 2010"
    (current-time-zone)
    (-25200 "MST")
    (float-time)
    1290398079.965001

    让我们进行一些转换:
    (decode-time (current-time))
    (33 7 21 21 11 2010 0 nil -25200)
    (decode-time) ; (current-time) by default
    (51 7 21 21 11 2010 0 nil -25200)

    (let ((seconds 36)
    (minutes 10)
    (hour 21)
    (day 21)
    (month 11)
    (year 2010))
    (encode-time seconds minutes hour day month year))
    (19689 60732)

    (format-time-string "%A %e %B" (current-time))
    "Sunday 21 November"

    (seconds-to-time 23)
    (0 23 0)

    (time-to-seconds (current-time))
    1290399309.598342

    (time-to-days (current-time))
    734097

    最后,回答您的问题:
    (time-add (current-time) (seconds-to-time 23))
    (19689 60954 497526)

    (time-subtract (current-time) (seconds-to-time 45))
    (19689 61001 736330)

    关于datetime - 如何使用Emacs Lisp在Emacs中添加日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4242012/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com