[plt-scheme] convert seconds to date, time?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Sep 14 14:30:39 EDT 2006

This is from the web-server collection:

   ; seconds->gmt-string : Nat -> String
   ; format is rfc1123 compliant according to rfc2068 (http/1.1)
   (define (seconds->gmt-string s)
     (let* ([local-date (seconds->date s)]
            [date (seconds->date (- s
                                    (date-time-zone-offset local-date)
                                    (if (date-dst? local-date) 3600  
       (format "~a, ~a ~a ~a ~a:~a:~a GMT"
               (vector-ref DAYS (date-week-day date))
               (two-digits (date-day date))
               (vector-ref MONTHS (sub1 (date-month date)))
               (date-year date)
               (two-digits (date-hour date))
               (two-digits (date-minute date))
               (two-digits (date-second date)))))

It logs based on GMT time.

For other date functionality, see


-- Matthias

On Sep 14, 2006, at 12:59 PM, Paul Graham wrote:

> Is there a way in mzscheme to convert a (current-seconds) time
> to a GMT date and time?
> I know this functionality must be buried in there somewhere,
> because there is a function seconds->date that does this and
> more (adjusting for the timezone your computer thinks it's
> in).  I just wonder if there is a way to get access to the
> underlying functionality for converting seconds to dates.
> If not this would be a useful thing to expose.  My own app
> is generating log files, and starts a new one each day.
> I'd rather do this based on days GMT, so that it doesn't break
> if someone happens to tell the computer it's in a new timezone.
> Also, if you had this, you could do date arithmetic: you
> could easily calculate e.g. what the date will be 1000 days
> from now.
> --pg
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.