如何格式化使用time-subtract
计算的时差值?考虑这个简单的例子:
(let*
((before (current-time))
(after (progn (sit-for 0.25) (current-time)))
(diff (time-subtract after before)))
(insert (format "before: %s--%s\n" before (format-time-string "%Hh%Mm%S.%3Ns" before)))
(insert (format "after: %s--%s\n" after (format-time-string "%Hh%Mm%S.%3Ns" after)))
(insert (format "diff: %s--%s--%s\n" diff (format-time-string "%s.%3Ns" diff)
(format-time-string "%Hh%Mm%S.%3Ns" diff))))
评估它会插入以下内容:
before: (22616 21856 296901 800000)--13h47m12.296s after: (22616 21856 552345 800000)--13h47m12.552s diff: (0 0 255444 0)--0.255s--16h00m00.255s
两个时间戳之间的差异大约是250毫秒。但是使用格式字符串format-time-string
的{{1}}格式化它会产生16。
不应该是0吗?
答案 0 :(得分:3)
"16"
来自您的时区。
我认为如果您执行(format-time-string "%Hh%Mm%S.%3Ns" diff 0)
,您会看到预期的结果(即0
)。