Previous: , Up: srfi time spec   [Index]


2.11.3.7 Date to string/string to date converters

The following procedures provide conversion to and from strings. They are required. The specification below describes a “locale”; the specification of locales is beyond this SRFI.

Function: date->string date
Function: date->string date format-string

Converts a date to a string, using the format string. The format string is copied as is; except escape characters (indicated by the tilde) are replaced with specific conversions. The following table lists the required conversion specifiers; implementations are free to extend this list.

Escape CharConversion
~~a literal ~
~alocale’s abbreviated weekday name (Sun...Sat)
~Alocale’s full weekday name (Sunday...Saturday)
~blocale’s abbreviate month name (Jan...Dec)
~Blocale’s full month day (January...December)
~clocale’s date and time (e.g., "Fri Jul 14 20:28:42-0400 2000")
~dday of month, zero padded (01...31)
~Ddate (mm/dd/yy)
~eday of month, blank padded ( 1...31)
~fseconds+fractional seconds, using locale’s decimal separator (e.g. 5.2).
~hsame as ~b
~Hhour, zero padded, 24-hour clock (00...23)
~Ihour, zero padded, 12-hour clock (01...12)
~jday of year, zero padded
~khour, blank padded, 24-hour clock (00...23)
~lhour, blank padded, 12-hour clock (01...12)
~mmonth, zero padded (01...12)
~Mminute, zero padded (00...59)
~nnew line
~Nnanosecond, zero padded
~plocale’s AM or PM
~rtime, 12 hour clock, same as "~I:~M:~S ~p"
~snumber of full seconds since "the epoch" (in UTC)
~Ssecond, zero padded (00...60)
~thorizontal tab
~Ttime, 24 hour clock, same as "~H:~M:~S"
~Uweek number of year with Sunday as first day of week (00...53)
~Vweek number of year with Monday as first day of week (01...52)
~wday of week (0...6)
~Wweek number of year with Monday as first day of week (01...52)
~xweek number of year with Monday as first day of week (00...53)
~Xlocale’s date representation, for example: "07/31/00"
~ylast two digits of year (00...99)
~Yyear
~ztime zone in RFC-822 style
~Zsymbol time zone (not–implemented)
~1ISO–8601 year–month–day format
~2ISO–8601 hour–minute–second-timezone format
~3ISO–8601 hour–minute–second format
~4ISO–8601 year–month–day–hour–minute–second–timezone format
~5ISO–8601 year–month–day–hour–minute–second format
Function: string->date input-string template-string

Convert an input string to a date, using the template string. The input string must match the template string as is; except escape characters (preceded by a the tilde) indicate special converters which (1) move to the next character in the input string fulfilling a criterion; (2) read a value, and (3) act on this value in some way. The table below lists the required converters; implementations are free to extend this list.

EscapeSkip toReadContract
~~anyread literal ~nothing
~achar-alphabetic?abbreviated weekday in localenothing
~Achar-alphabetic?full weekday in localenothing
~bchar-alphabetic?abbreviated month name in localenothing
~Bchar-alphabetic?full month name in localenothing
~dchar-numeric?day of monthdate–day
~eanyday of month, blank paddeddate–day
~hchar-alphabetic?same as ~bnothing
~Hchar-numeric?hourdate–hour
~kanyhour, blank paddeddate–hour
~mchar-numeric?monthdate–month
~Mchar-numeric?minutedate–minute
~Schar-numeric?seconddate–second
~yany2–digit yeardate–year within 50 years
~Ychar-numeric?yeardate-year
~zanytime zonedate–zone–offset

Previous: , Up: srfi time spec   [Index]