Parsing formatted time string (inverse of format-time-string) asks for a complete inverse of format-time-string with the ability to specify the source format, but I really just need to get from a UNIX time / epoch time to a real time value (like that which (current-time) returns.

In essence, I want the following:

(let* ((emacs-time (current-time))
       (unix-time  (string-to-number (format-time-string "%s" emacs-time))))
  (equal emacs-time (mystery-func unix-time)))

1 Answer 1


In keeping with tradition, I was able to find the answer in Emacs itself while asking this question.

It turns out the standard time functions work with different kinds of values:

Function arguments, e.g., the TIME argument to current-time-string, accept a more-general "time value" format, which can be a list of integers as above, or a single number for seconds since the epoch, or nil for the current time. You can convert a time value into a human-readable string using current-time-string and format-time-string, into a list of integers using seconds-to-time, and into other forms using decode-time and float-time. These functions are described in the following sections.

So, seconds-to-time will do what's needed. Note that since (current-time) returns microseconds as well – something not present in most UNIX timestamps – the assertion in the question won't hold as-written. If you strip microseconds from (current-time), though, they'll be the same :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.