Next: , Previous: SRFI-19 Time/Date conversions, Up: SRFI-19


6.4.15.5 SRFI-19 Date to string

— Function: date->string date [format]

Convert a date to a string under the control of a format. format should be a string containing ‘~’ escapes, which will be expanded as per the following conversion table. The default format is ‘~c’, a locale-dependent date and time.

Many of these conversion characters are the same as POSIX strftime (see Time), but there are some extras and some variations.

~~ literal ~
~a locale abbreviated weekday, eg. ‘Sun
~A locale full weekday, eg. ‘Sunday
~b locale abbreviated month, eg. ‘Jan
~B locale full month, eg. ‘January
~c locale date and time, eg.
Fri Jul 14 20:28:42-0400 2000
~d day of month, zero padded, ‘01’ to ‘31


~e day of month, blank padded, ‘ 1’ to ‘31
~f seconds and fractional seconds, with locale decimal point, eg. ‘5.2
~h same as ~b
~H hour, 24-hour clock, zero padded, ‘00’ to ‘23
~I hour, 12-hour clock, zero padded, ‘01’ to ‘12
~j day of year, zero padded, ‘001’ to ‘366
~k hour, 24-hour clock, blank padded, ‘ 0’ to ‘23
~l hour, 12-hour clock, blank padded, ‘ 1’ to ‘12
~m month, zero padded, ‘01’ to ‘12
~M minute, zero padded, ‘00’ to ‘59
~n newline
~N nanosecond, zero padded, ‘000000000’ to ‘999999999
~p locale AM or PM
~r time, 12 hour clock, ‘~I:~M:~S ~p
~s number of full seconds since “the epoch” in UTC
~S second, zero padded ‘00’ to ‘60
(usual limit is 59, 60 is a leap second)
~t horizontal tab character
~T time, 24 hour clock, ‘~H:~M:~S
~U week of year, Sunday first day of week, ‘00’ to ‘52
~V week of year, Monday first day of week, ‘01’ to ‘53
~w day of week, 0 for Sunday, ‘0’ to ‘6
~W week of year, Monday first day of week, ‘00’ to ‘52


~y year, two digits, ‘00’ to ‘99
~Y year, full, eg. ‘2003
~z time zone, RFC-822 style
~Z time zone symbol (not currently implemented)
~1 ISO-8601 date, ‘~Y-~m-~d
~2 ISO-8601 time+zone, ‘~k:~M:~S~z
~3 ISO-8601 time, ‘~k:~M:~S
~4 ISO-8601 date/time+zone, ‘~Y-~m-~dT~k:~M:~S~z
~5 ISO-8601 date/time, ‘~Y-~m-~dT~k:~M:~S

Conversions ‘~D’, ‘~x’ and ‘~X’ are not currently described here, since the specification and reference implementation differ.

Currently Guile doesn't implement any localizations for the above, all outputs are in English, and the ‘~c’ conversion is POSIX ctime style ‘~a ~b ~d ~H:~M:~S~z ~Y’. This may change in the future.