help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The wild and weird world of Emacs Lisp date/time arithmetic


From: Stefan Möding
Subject: Re: The wild and weird world of Emacs Lisp date/time arithmetic
Date: Thu, 17 Dec 2020 21:35:57 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin)

Skip Montanaro <skip.montanaro@gmail.com> writes:

> Still, it seems there should be an inverse to parse-time-string which
> consumes a format string and one of those n-element lists. I'm thinking in
> terms of C stdio functions strptime and strftime, or the methods of the
> same name for Python's datetime objects. That's what fooled me about the
> format-time-string function. Its name implies that it would consume the
> output of parse-time-string but it doesn't.

`format-time-string’ seems to use Lisp timestamps which can be created
with `encode-time’.  The following seems to solve your initial problem:

(format-time-string
 "%Y-%m-%d"
 (encode-time (decoded-time-add (parse-time-string "2020-05-17")
                                (make-decoded-time :day 1))))


Yes, it probably should be easier to do...

-- 
Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]