On this page:
~t
9.0
top
up

15Formatting and Parsing🔗 i

15.1Formatting Dates and Times🔗 i

procedure

( ~t tpattern[#:localelocale])string?

pattern:string?
Formats t using the given pattern. The pattern syntax is specified by CLDR.

Examples:
(displayln (~t (date 19551112)"E, MMMM d, y G"))
(displayln (~t (datetime 1955111224230)"E h:mm a")))

Sat, November 12, 1955 AD

Sat 2:42 AM

(displayln (~t (date 19551112)"E d MMM y G"))
(displayln (~t (datetime 1955111224230)"E h:mm:ss a")))

sam. 12 nov. 1955 ap. J.-C.

sam. 2:42:30 AM

15.2Parsing Dates and Times🔗 i

15.2.1Parsing ISO 8601 representations🔗 i

procedure

( iso8601->date str)date?

str:string?
Parses an ISO 8601 representation of a date into a date . Note that the input must use the ISO 8601 extended format.

Examples:
> (iso8601->date "1981-04-05")

#<date 1981年04月05日>

> (iso8601->date "1981-04")

#<date 1981年04月01日>

procedure

( iso8601->time str)date?

str:string?
Parses an ISO 8601 representation of a time into a time . Note that the input must use the ISO 8601 extended format.

Example:
> (iso8601->time "13:47:30")

#<time 13:47:30>

procedure

( iso8601->datetime str)date?

str:string?
Parses an ISO 8601 combined date and time representation into a datetime . Note that the input must use the ISO 8601 extended format.

Example:
> (iso8601->datetime "2014-03-20T19:20:09.3045")

#<datetime 2014年03月20日T19:20:09.3045>

procedure

( iso8601->moment str)date?

str:string?
Parses an ISO 8601 combined date and time representation into a moment . Note that the input must use the ISO 8601 extended format.

Example:
> (iso8601->moment "2014-03-20T19:20:09.3045Z")

#<moment 2014年03月20日T19:20:09.3045Z>

procedure

( iso8601/tzid->moment str)date?

str:string?
Parses a non-standard format, consisting of an ISO 8601 combined date and time representation and an IANA time zone ID in brackets, into a moment . The input format is the same as that produced by moment->iso8601/tzid . Note that the ISO 8601 portion of the input must use the ISO 8601 extended format.

Example:
> (iso8601/tzid->moment "2014-03-20T19:20:09.3045-04:00[America/New_York]")

#<moment 2014年03月20日T19:20:09.3045-04:00[America/New_York]>

15.2.2Flexible parsing based on patterns🔗 i

procedure

( parse-date str
pattern
[ #:ci?ci?
#:localelocale])date?
str:string?
pattern:string?
ci?:boolean? =#t
Parses str according to pattern, which uses the CLDR pattern syntax. The result is returned as a date . If the input cannot be parsed as a date , exn:gregor:parse is raised.

Example:
(list
(parse-date "January 24, 1977""LLLL d, y")
(parse-date "2015-03-15T02:02:02-04:00""yyyy-MM-dd'T'HH:mm:ssxxx")))

'(#<date 1977年01月24日> #<date 2015年03月15日>)

procedure

( parse-time str
pattern
[ #:ci?ci?
#:localelocale])time?
str:string?
pattern:string?
ci?:boolean? =#t
Parses str according to pattern, which uses the CLDR pattern syntax. The result is returned as a time . If the input cannot be parsed as a time , exn:gregor:parse is raised.

Example:
(list
(parse-time "January 24, 1977""LLLL d, y")
(parse-time "2015-03-15T02:02:02-04:00""yyyy-MM-dd'T'HH:mm:ssxxx")))

'(#<time 00:00:00> #<time 02:02:02>)

procedure

pattern
[ #:ci?ci?
#:localelocale])datetime?
str:string?
pattern:string?
ci?:boolean? =#t
Parses str according to pattern, which uses the CLDR pattern syntax. The result is returned as a datetime . If the input cannot be parsed as a datetime , exn:gregor:parse is raised.

Example:
(list
(parse-datetime "January 24, 1977""LLLL d, y")
(parse-datetime "2015-03-15T02:02:02-04:00""yyyy-MM-dd'T'HH:mm:ssxxx")))

'(#<datetime 1977年01月24日T00:00:00> #<datetime 2015年03月15日T02:02:02>)

procedure

( parse-moment str
pattern
[ #:ci?ci?
#:localelocale]
#:resolve-offsetresolve)moment?
str:string?
pattern:string?
ci?:boolean? =#t
Parses str according to pattern, which uses the CLDR pattern syntax. The result is returned as a moment . If the input cannot be parsed as a moment , exn:gregor:parse is raised. If the result’s UTC offset is ambigous, resolve is used to resolve the ambiguity.

Example:
[current-timezone "Pacific/Honolulu"])
(list
(parse-moment "January 24, 1977""LLLL d, y")
(parse-moment "2015-03-15T02:02:02-04:00""yyyy-MM-dd'T'HH:mm:ssxxx")))

'(#<moment 1977年01月24日T00:00:00-10:00[Pacific/Honolulu]>

#<moment 2015年03月15日T02:02:02-04:00>)

A parameter used to control how parsed two-digit years are resolved into complete years. The default implementation is:
(λ (parsed-year)
(define current-year(->year (now )))
(define lo(- current-year50))
(define t(if (>= lo0)
(remainder lo100)
(+ 99(remainder (add1 lo)100))))
(+ parsed-year
lo
(if (< parsed-yeart)
100
0)
(- t)))

Example:
(parse-date "3/3/33""M/d/yy"))

#<date 3333年03月03日>

top
up

AltStyle によって変換されたページ (->オリジナル) /