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

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

Re: How to read a timestamp?


From: Emanuel Berg
Subject: Re: How to read a timestamp?
Date: Wed, 12 Aug 2015 04:56:52 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Marcin Borkowski <mbork@mbork.pl> writes:

> I need to ask the user for a date (with or without
> time - if no time is supplied, I want to assume
> 9:00am). I know that `org-read-date' is quite
> a powerful way to do it, but what if I do not want
> to depend on Org-mode?

I wrote something to that extent a while back:

    http://user.it.uu.se/~embe8573/conf/emacs-init/time-my.el

Here is the relevant Elisp. (To add "time", change the
arguments to `encode-time'.)


(defun time-between-times (year1 month1 day1
                           year2 month2 day2)
  (let*((seconds-then  (float-time (encode-time 0 0 0 day1 month1 year1)))
        (seconds-now   (float-time (encode-time 0 0 0 day2 month2 year2)))
        (seconds-diff  (- seconds-now seconds-then)) )
    (format-seconds "%Y, %D" seconds-diff)))

(defun print-time-since (year month day)
  (format-seconds "%Y, %D" (float-time
                            (time-since (encode-time 0 0 0 day month year)))) )

;; test:
;;   (time-between-times 2010 4 15 2015 3 16)
;;   (print-time-since 2010 4 15)


You are welcome :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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