encode-universal-time
encode-universal-time function
Syntax:
encode-universal-time second minute hour date month year
&optional time-zone
→ universal-time
Arguments and Values:
second, minute, hour, date, month, year, time-zone—the corresponding parts of a decoded time. (Note that some of the nine values in a full decoded time are redundant, and so are not used as inputs to this function.)
universal-time—a universal time.
Description:
encode-universal-time converts a time from Decoded Time format to a universal time. If time-zone is supplied, no adjustment for daylight savings time is performed.
Examples:
(encode-universal-time 0 0 0 1 1 1900 0) → 0
(encode-universal-time 0 0 1 4 7 1976 5) → 2414296800
;; The next example assumes Eastern Daylight Time.
(encode-universal-time 0 0 1 4 7 1976) → 2414293200
See Also:
decode-universal-time, get-decoded-time
Expanded Reference: encode-universal-time
Encoding time components into universal time
encode-universal-time converts individual time components into a universal time integer.
;; Encode midnight January 1, 2000 UTC
(encode-universal-time 0 0 0 1 1 2000 0)
=> 3155673600
Round-trip with decode-universal-time
Encoding and then decoding yields the original components.
(multiple-value-bind (sec min hour day month year)
(decode-universal-time
(encode-universal-time 30 45 14 25 12 2024 0) 0)
(list year month day hour min sec))
=> (2024 12 25 14 45 30)
Using the local time zone
When the time-zone argument is omitted, the local time zone is assumed.
;; Encode in local time
(integerp (encode-universal-time 0 0 12 1 6 2025))
=> T
Encoding the epoch
Universal time 0 corresponds to midnight January 1, 1900 GMT.
(encode-universal-time 0 0 0 1 1 1900 0)
=> 0
Computing time differences
Universal times are integers, so you can compute differences directly.
(let ((t1 (encode-universal-time 0 0 0 1 1 2025 0))
(t2 (encode-universal-time 0 0 0 2 1 2025 0)))
(/ (- t2 t1) 3600))
=> 24