You need to find the year, month, and day values for today's date.
Use
current-seconds, and
seconds->date to get a date structure
type representing today.
(let* ((seconds (current-seconds))
(today (seconds->date seconds)))
(values
(date-day today)
(date-month today)
(date-year today)))
Using the
date library from Mzlib, you can easily convert a date
structure to a string.
(require (lib "date.ss"))
(let* ((seconds (current-seconds))
(today (seconds->date seconds)))
(date->string today))
which will return something like
"Wednesday, April 21st, 2004". The
returned string contains the time of day only if the second, optional,
argument to
date->string is
#t, so, using =(date->string today
#t)= above would return:
"Wednesday, April 21st, 2004 12:54:20pm".
SRFI 19 provides equivalent funciontallity, and much more. Thus if
you would want to use the
time.ss library from the
srfi
collection, to get today's date you could do:
(require (lib "date.ss"))
(let* ((seconds (current-seconds))
(today (seconds->date seconds)))
(date->string today))
which will return
"Wed Apr 21 13:01:01-0500 2004".
Note that the format returned by these
different date->string
procedures, the former from the Mzlib collection, the later from
SRFI-19, differs. The number of arguments these procedures receive
also differs, the one form
SRFI-19 supports localization, the other
one not, etc.
To change the format of the returning string using Mzlib, you need to
use
(date-display-format [format-symbol]), with one of the supported
format symbols: ='american, 'chinese, 'german, 'indian, 'irish,
'iso-8601, 'rfc2822=, or
'julian. The initial format is
'american.
For instance,
(require (lib "date.ss"))
(let* ((seconds (current-seconds))
(today (seconds->date seconds)))
(date-display-format 'iso-8601)
(date->string today))
which would return
"2004-04-21".
To change the format using
SRFI-19 accordingly, you have to instruct
date->string using its second, optional, argument.
(require (lib "19.ss" "srfi"))
(let ((today (current-date)))
(date->string today "~1"))
If you are using
DrScheme, then use Help Desk to access the
MzScheme
manual, and the documentation for
SRFI-19.
--
FranciscoSolsona - 28 Apr 2004