How to add dates to Emacs using Emacs Lisp?

I want to use Emacs Lisp to perform mathematical operations, such as adding and distinguishing by date and time.

+7
datetime emacs elisp
source share
1 answer

Short answer: read the "System Interface" section of the elisp manual. More specifically, time sections:

Longer answer:

Emacs can work with time values โ€‹โ€‹as strings, floats, or tuples of two or three integers. For example. call some functions in the *scratch* buffer:

 (current-time) (19689 59702 984160) (current-time-string) "Sun Nov 21 20:54:22 2010" (current-time-zone) (-25200 "MST") (float-time) 1290398079.965001 

Let some transformations:

 (decode-time (current-time)) (33 7 21 21 11 2010 0 nil -25200) (decode-time) ; (current-time) by default (51 7 21 21 11 2010 0 nil -25200) (let ((seconds 36) (minutes 10) (hour 21) (day 21) (month 11) (year 2010)) (encode-time seconds minutes hour day month year)) (19689 60732) (format-time-string "%A %e %B" (current-time)) "Sunday 21 November" (seconds-to-time 23) (0 23 0) (time-to-seconds (current-time)) 1290399309.598342 (time-to-days (current-time)) 734097 

Finally, to answer your question:

 (time-add (current-time) (seconds-to-time 23)) (19689 60954 497526) (time-subtract (current-time) (seconds-to-time 45)) (19689 61001 736330) 
+15
source share

All Articles