s c h e m a t i c s : c o o k b o o k

/ TimeRecipes / Cookbook.TimeToday

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Finding Today's Date

Problem

You need to find the year, month, and day values for today's date.

Solution

Use current-seconds, and seconds->date to get a date structure type representing today.

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

Discussion

Using the date library from Mzlib, you can easily convert a date structure to a string.

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

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:

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

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,

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

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.

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

See Also

If you are using DrScheme, then use Help Desk to access the MzScheme manual, and the documentation for SRFI-19.

Comments here

-- FranciscoSolsona - 28 Apr 2004

CookbookForm
TopicType: Recipe
ParentTopic: TimeRecipes
TopicOrder: 010

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest