On this page:
9.0
top
up

9Generic Datetime Operations🔗 i

An interface, implemented by datetime , and moment , that supplies generic operations on datetimes.

In fact, gen:datetime-provider is also implemented by date , which can be treated like a datetime with its time component set to midnight. This should be considered an experimental part of the design, which may be removed.

procedure

( datetime-provider? x)boolean?

x:any/c
Returns #t if x implements gen:datetime-provider ; #f otherwise.

procedure

( ->datetime/local t)datetime?

Returns the local datetime corresponding to t.

Examples:
> (->datetime/local (datetime 1969721256))

#<datetime 1969年07月21日T02:56:00>

> (->datetime/local (moment 2015381#:tz"America/New_York"))

#<datetime 2015年03月08日T01:00:00>

procedure

( ->datetime/utc t)datetime?

Returns the UTC datetime corresponding to t.

For a datetime , ->datetime/local and ->datetime/utc return the same thing.

Examples:
> (->datetime/utc (datetime 1969721256))

#<datetime 1969年07月21日T02:56:00>

> (->datetime/utc (moment 2015381#:tz"America/New_York"))

#<datetime 2015年03月08日T06:00:00>

procedure

( ->posix t)rational?

Returns the number of seconds between the UNIX epoch (UTC midnight on January 1, 1970) and t, expressed as a rational number.

Examples:
> (->posix (datetime 1970))

0

> (->posix (moment 2015381#:tz"America/New_York"))

1425794400

procedure

( ->jd t)rational?

Returns the number of days since the Julian epoch (noon on November 24, 4714 BCE in the proleptic Gregorian calendar), expressed as a rational number.

Examples:
> (->jd (moment -4713112412#:tz"Etc/UTC"))

0

> (->jd (datetime 1970))

4881175/2

Returns the duration between the given date providers, in terms of the chosen unit. These functions follow the same rules as date and time arithmetic. So, for example, there is exactly one year between successive January 1sts, whether or not the actual span is 365 or 366 days.

Examples:
> (years-between (datetime 2000)(datetime 2001))

1

> (years-between (datetime 2001)(datetime 2002))

1

> (months-between (datetime 20003)(datetime 199912))

-3

> (days-between (moment 201538159#:tz"America/Los_Angeles")
(moment 2015316159#:tz"America/Los_Angeles"))

8

> (weeks-between (moment 201538159#:tz"America/Los_Angeles")
(moment 2015316159#:tz"Etc/UTC"))

1

> (days-between (datetime 2015)(datetime 2015114235959))

13

> (hours-between (moment 2000#:tz"Etc/UTC")
(moment 1999123119#:tz"America/New_York"))

0

> (minutes-between (datetime 2000)(datetime 200012))

1440

> (seconds-between (datetime 2000)(datetime 200012))

86400

86400000

86400000000

86400000000000

procedure

tz
#:resolve-offsetresolve-offset)
tz:tz/c
resolve-offset:offset-resolver/c
Attaches tz to the local datetime component of t. Note that if t starts with any timezone information, it is discarded.

This function is a blunt instrument and is rarely needed. If your aim is to translate a moment into another that represents the same point in absolute time but in a different time zone, then you’re looking for adjust-timezone .

Examples:
> (with-timezone (datetime 2000)"America/New_York")

#<moment 2000年01月01日T00:00:00-05:00[America/New_York]>

> (with-timezone (moment 2000#:tz"America/New_York")"Europe/Paris")

#<moment 2000年01月01日T00:00:00+01:00[Europe/Paris]>

top
up

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