[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Current date & time?
From: |
Jim Ursetto |
Subject: |
Re: [Chicken-users] Current date & time? |
Date: |
Thu, 28 May 2009 11:02:45 -0500 |
On Thu, May 28, 2009 at 8:57 AM, Mario Domenech Goulart
<address@hidden> wrote:
> On Thu, 28 May 2009 07:32:04 -0600 Matt Gushee <address@hidden> wrote:
>
>> I thought I would create a simple logging facility, and, well of
>> course every good log entry needs a timestamp ... so I searched for a
>> function to get the current date and/or time
> csi> (use posix)
> csi> (seconds->string (current-seconds))
> "Thu May 28 10:53:38 2009"
SRFI-19 is another possibility for Chicken 3, although it is rather heavyweight.
However you can find standalone timestamp examples in the egg repo;
below is a simple one from phricken:
#;> (utc->seconds (current-seconds))
"2009-05-28 15:48:33"
;; Convert seconds since UNIX epoch into string in format "yy-mm-dd HH:MM:SS".
;; Seconds are interpreted as UTC time.
(define (utc-seconds->string seconds)
(define (w2 x)
(if (< x 10) (sprintf "0~a" x) (sprintf "~a" x)))
(let* ((v (seconds->utc-time seconds))
(g (lambda (x) (vector-ref v x))))
(conc
(+ (g 5) 1900) "-" (w2 (+ (g 4) 1)) "-" (w2 (g 3)) " " ; yyyy-mm-dd
(w2 (g 2)) ":" (w2 (g 1)) ":" (w2 (g 0))))) ; HH:MM:SS