ミリ秒まで含んだ時刻文字列
Posted feedbacks - Common Lisp
間違えましたCommonLispです
1 2 | (defun todaydate ()
(princ (cdr (cdr (cdr(reverse (multiple-value-list (get-decoded-time))))))))
|
CLでは、秒より細かい単位で時間を取得できますが、
その粒度は処理系依存のようです。
SBCLとCLISPに対応してみました。
(get-universal-time+millisecond-string)
;==> "20080711160627.511"
その粒度は処理系依存のようです。
SBCLとCLISPに対応してみました。
(get-universal-time+millisecond-string)
;==> "20080711160627.511"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | (defconstant +unix-time-origin+ (encode-universal-time 0 0 0 1 1 1970 0))
(defun get-universal-time+millisecond-string ()
(multiple-value-bind (time ms)
#+sbcl (sb-unix::system-real-time-values)
#+clisp (floor (get-internal-real-time) internal-time-units-per-second)
(multiple-value-bind (s m h d mo y)
(decode-universal-time (+ +unix-time-origin+ time))
(format nil "~D~2,'0D~2,'0D~2,'0D~2,'0D~2,'0D.~A"
y mo d h m s (truncated-millisecond-string ms)))))
(defmacro truncated-millisecond-string (n)
(let* ((fig (1- (length
(princ-to-string internal-time-units-per-second))))
(form `(format nil ,(format nil "~~~D,'0D" fig) ,n)))
(if (= 3 fig)
form
`(subseq ,form 0 3))))
|




znz #6446() Rating0/0=0.00
YYYY年mm月dd日HH時MM分SS.xxx秒なら、「YYYYmmddHHMMSS.xxx」のようにミリ秒まで含んだ文字列を返すプログラムを書いてください。
[ reply ]