File: format-time

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (27 lines) | stat: -rw-r--r-- 963 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
S9 LIB  (format-time string time-list)  ==>  string | #f

Format the time specification TIME-LIST (as returned by the
UNIX-TIME->TIME procedure) according to the description in
STRING. This a poor man's CommonLISP FORMAT-style procedure
intended for making time lists more readable. It returns #F
if TIME-LIST is not a proper time list or string is erroneous
(i.e.: contains a wrong format descriptor). The following
format descriptors are supported:

        ~w   day of week (Mon, Tue, ...)
        ~y   year
        ~:m  number of month
        ~@m  month name (Jan, Feb, ...)
        ~h   hour
        ~m   minute
        ~s   second
        ~~   literal ~

When a single digit appears between a ~ and the rest of a
format descriptor, this digit will be interpreted as a length
and the resulting string will be padded to this length with
zeros.

(format-time "~w ~4y-~@m-~2d ~2h:~2m:~2s"
             '(1 2009 3 9 8 53 20))
    ==> "Tue 2009-Mar-09 08:53:20"