[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Current time as floating point number
From: |
Hrvoje Niksic |
Subject: |
Current time as floating point number |
Date: |
18 Oct 2005 15:45:20 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
For a while now I've been using the following function:
(defun current-time-as-float ()
(let ((tm (current-time)))
(+
(* 65536.0 (nth 0 tm))
(nth 1 tm)
(/ (nth 2 tm) 1000000.0))))
(current-time-as-float)
--> 1129642168.966545
It returns the current time as a single floating-point number. I find
it very convenient because its return value can be manipulated with
normal arithmetic functions, such as subtraction. This is useful for
measuring of passage of time, as well as for recording time stamps.
The truncated value can also be passed to external code that expects
the Unix-style number of seconds since Epoch.
While the above function wasn't hard to write for me, it probably
would be for a beginner. I'm not proposing that you include the above
function as-is, but such functionality in some form, either as
an optional argument to current-time, or as a separate (more
aptly-named) function would be useful.
Later, functions like format-time-string could start accepting such
floating-point arguments as well.
- Current time as floating point number,
Hrvoje Niksic <=