use*_*324 4 formatting date common-lisp
I am trying to get the current system date in Common Lisp through following function
(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)))
Run Code Online (Sandbox Code Playgroud)
Unfortunately I am getting the current date in this format "2014-1-2". However actually I need this format "2014-01-02". Is any way we can change the format? I tried replacing nil with yyyy-mm-dd but no luck. However my machine clock shows the date format is "2014-01-02".
(format nil "~4,'0d-~2,'0d-~2,'0d" yr mon day)
Run Code Online (Sandbox Code Playgroud)
~2,'0d means:
d: decimal output (instead of your generic a)2: 1st argument: width'0: 2nd argument: pad char 0I suggest that you read up on Formatted Output; format is a very powerful tool.