13.  Date and Time  

(unix-time)

The UNIX time() function. unix-time returns the number of seconds elapsed since midnight UTC, January 1, 1970 (The Epoch) as an integer.

(unix-nanotime)

This procedure returns the number of nanoseconds elapsed since The Epoch as an integer. unix-nanotime invokes one of the UNIX functions gettimeofday(), ftime(), time() (in that order, depending on which of these function is available), thus providing up to microsecond resolution.

(unix-decode-localtime time)
(unix-decode-utc time)

Both procedures convert the specified time (a number of seconds as returned by unix-time) into a time-record; unix-decode-localtime corrects for the local time zone and DST adjustment (based on the UNIX localtime() and gmtime() functions).

A time-record has the following fields:

+-------------+---------+--------------------+
|   Field     |  Type   |       Range        |
+-------------+---------+--------------------+
+-------------+---------+--------------------+
|seconds      | integer | 0..61              |
+-------------+---------+--------------------+
|minutes      | integer | 0..59              |
+-------------+---------+--------------------+
|hours        | integer | 0..23              |
+-------------+---------+--------------------+
|day-of-month | integer | 1..31              |
+-------------+---------+--------------------+
|month        | integer | 0..11              |
+-------------+---------+--------------------+
|year         | integer | (year - 1900)      |
+-------------+---------+--------------------+
|weekday      | integer | 0..6               |
+-------------+---------+--------------------+
|day-of-year  | integer | 0..365             |
+-------------+---------+--------------------+
|dst          | integer | 1 if DST in effect |
+-------------+---------+--------------------+

Example:

;;; Return date as a string of the form "Nov 3, 1993"
(define (date-string)
  (let* ((months "JanFebMarAprMayJunJulAugSepOctNovDec")
         (time (unix-decode-localtime (unix-time)))
         (month-inx (* 3 (time-month time))))
    (format #f "~a ~a, ~a"
            (substring months month-inx (+ 3 month-inx))
            (time-day-of-month time) (+ 1900 (time-year time)))))

(unix-time->string time)

This procedure converts the specified time into a string; it is based on the ctime() and asctime() UNIX functions. time is either an integer (number of seconds) or a time-record.


Markup created by unroff 1.0,    September 24, 1996,    net@informatik.uni-bremen.de