Next: Time Parsing, Previous: Current Time, Up: Time [Index]
Functions that convert time values to Lisp timestamps or to calendrical information. Calendrical conversion functions always use the Gregorian calendar, even for dates before the Gregorian calendar was introduced. Year numbers count the number of years since the year 1 BC, and do not skip zero as traditional Gregorian years do; for example, the year number -37 represents the Gregorian year 38 BC.
time-convert
—Time Value to Lisp TimestampThis function converts a time value into a Lisp timestamp.
(time-convert nil nil)
is equivalent to
(current-time)
but the latter is a bit faster.
The optional form argument specifies the timestamp form to be returned.
this function returns an integer count of seconds.
it specifies a clock frequency and this function returns an integer-pair timestamp ‘(ticks . form)’.
this function treats it as a positive integer suitable for representing the timestamp; for example, it is treated as 1000000000 if time is ‘nil’ and the platform timestamp has nanosecond resolution.
this function returns an integer list ‘(high low micro pico)’.
currently acts like ‘’list’9
When form is ‘t’, conversion is always exact so no truncation occurs, and the returned clock resolution is no less than that of time.
if time cannot be represented exactly, conversion truncates it toward minus infinity.
this function signals an error
By way of contrast, float-time
can convert any Lisp time value without
signaling an error, although the result might not be exact.
decode-time
—Time Value to Calendrical InfoThis function converts a time value into calendrical information of the form:
(seconds minutes hour day month year dow dst utcoff)
Defaults to the current time.
Defaults to the current time zone rule.
Controls the form of the returned ‘seconds’ element.
The ‘seconds’ element is a Lisp timestamp that is nonnegative and less than 61; it is less than 60 except during positive leap seconds
If the optional ‘form’ argument is ‘t’, seconds uses the same precision as time;
If ‘form’ is ‘’integer’, ‘seconds’ is truncated to an integer.
If ‘form’ is omitted or ‘nil’, it currently defaults to integer10
The return value is a list of nine elements:
(seconds minutes hour day month year dow dst utcoff)
To access (or alter) the elements in the ‘TIME’ value, these accessors can be used.
decoded-time-second
decoded-time-minute
decoded-time-hour
decoded-time-day
decoded-time-month
decoded-time-year
decoded-time-weekday
decoded-time-dst
decoded-time-zone
decoded-time-add
This function takes a decoded time structure and adds ‘DELTA’ (also a decoded time structure) to it.
Elements in ‘DELTA’ that are ‘nil’ are ignored. Fields are added in a most to least significant order. The values in ‘DELTA’ can be negative to subtract values instead.
For instance, if you want “same time next month”, you could say:
(let ((time (decode-time nil nil t)) (delta (make-decoded-time :month 2))) (encode-time (decoded-time-add time delta)))
If this date doesn’t exist (if you’re running this on January 31st, for instance), then the date will be shifted back until you get a valid date (which will be February 28th or 29th, depending).
The return value is a decoded time structure.
make-decoded-time
Return a decoded time structure with only the given keywords filled out, leaving the rest ‘nil’. To get a structure that represents “two months”, you could say:
(make-decoded-time :month 2)
encode-time
This function converts ‘TIME’ to a Lisp timestamp. It can act as the inverse
of decode-time
. You can perform simple date arithmetic by using out-of-range
values for seconds, minutes, hour, day, and month; for example, day 0 means
the day preceding the given month.
Ordinarily the first argument is a list that specifies a decoded
time in the style of decode-time
:
(second minute hour day month year ignored dst zone)
As an obsolescent calling convention, this function can be given six or more arguments. The first six arguments second, minute, hour, day, month, and year specify most of the components of a decoded time. If there are more than six arguments the last argument is used as ‘ZONE’ and any other extra arguments are ignored.
this is planned to change in a future Emacs version, so callers requiring list timestamps should pass list explicitly.
This default may change in future Emacs releases, so callers requiring a particular form should specify form.
Next: Time Parsing, Previous: Current Time, Up: Time [Index]