gpt4 book ai didi

date - 在 Common Lisp 中格式化当前系统日期

转载 作者:行者123 更新时间:2023-12-05 00:27:22 25 4
gpt4 key购买 nike

我正在尝试通过以下函数获取 Common Lisp 中的当前系统日期

(defun current-date-string ()
"Returns current date as a string."
(multiple-value-bind (sec min hr day mon yr dow dst-p tz)
(get-decoded-time)
(declare (ignore sec min hr dow dst-p tz))
(format nil "~A-~A-~A" yr mon day)))

不幸的是,我以“2014-1-2”这种格式获取当前日期。但是实际上我需要这种格式“2014-01-02”。有什么办法可以改变格式吗?我尝试用 yyyy-mm-dd 替换 nil 但没有运气。但是我的机器时钟显示日期格式是“2014-01-02”。

最佳答案

What you need is

(format nil "~4,'0d-~2,'0d-~2,'0d" yr mon day)
~2,'0d方法:
  • d :十进制输出(而不是您的通用 a)
  • 2 :第一个参数:宽度
  • '0 :第二个参数:填充字符 0

  • 我建议你阅读 Formatted Output ; format是一个非常强大的工具。

    关于date - 在 Common Lisp 中格式化当前系统日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20875737/

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