在 Common Lisp 中格式化包含 GMT 偏移量的时间戳?

问题描述 投票:0回答:1

使用带有“local-time”包的common lisp,我尝试格式化包含GMT偏移量的时间戳。该文档包含“:gmt-offset”格式参数,但使用它会生成错误。我查看了github上的源代码,case语句似乎包含:gmt-offset。难道我做错了什么?我是否获得了没有 gmt 偏移的旧版本当地时间?

(ql:quickload "local-time")
(local-time:format-timestring nil (local-time:now) :format
    '((:year 4)  #\.
      (:month 2) #\.
      (:day 2)   #\.
      (:hour 2)  #\.
      (:min 2)   #\.
      (:sec 2)   #\.
      (:msec 3)  #\-
      (:gmt-offset)))

在 SBCL 2.3.4 中加载它会给我:

debugger invoked on a SB-KERNEL:CASE-FAILURE @225F39AB in thread #<THREAD "main thread" RUNNING {10044C00A3}>: :GMT-OFFSET fell through ECASE expression. Wanted one of (:NSEC :USEC :MSEC :SEC :MIN :HOUR :HOUR12 :DAY :WEEKDAY :MONTH :YEAR :ISO-WEEK-YEAR ...).

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

(LOCAL-TIME::%CONSTRUCT-TIMESTRING #<unavailable argument> #<unavailable argument> #<unavailable argument>)
   source: (ECASE (IF (CONSP FMT) (CAR FMT) FMT) (:NSEC NSEC) (:USEC (FLOOR NSEC 1000)) (:MSEC (FLOOR NSEC 1000000)) (:SEC SEC) (:MIN MINUTE) (:HOUR HOUR) (:HOUR12 (1+ (MOD (1- HOUR) 12))) (:DAY DAY) (:WEEKDAY WEEKDAY) (:MONTH MONTH) ...)
timestamp lisp common-lisp gmt
1个回答
1
投票

我找到了答案。我只需删除 :gmt-offset 周围的括号。我猜它不支持那里的填充参数。这是一个一致性问题,还有一个文档问题,也许应该有一个例子。

我会把它留在这里,以防其他人遇到这个问题。

正确的格式是:

(ql:quickload "local-time")
(local-time:format-timestring nil (local-time:now) :format
                  '((:year 4) #\.
                (:month 2) #\.
                (:day 2) #\.
                (:hour 2) #\.
                (:min 2) #\.
                (:sec 2) #\.
                (:msec 3) #\-
                :gmt-offset
                ))
© www.soinside.com 2019 - 2024. All rights reserved.