4

By default display-time-mode shows the time only in minutes. How I can display time in seconds? Something like 18:34:45".

  • 1
    Keywords: format-time-string and mode-line-format and emacs – lawlist Jan 5 '15 at 23:28
6

The top of the EmacsWiki page on Display Time tells you how to control the format of the time.

Of the three variables, it looks like display-time-format is the most relevant after inspecting the docstrings of the variables with C-h v display-time-format:

String specifying format for displaying the time in the mode line. See the function format-time-string for an explanation of how to write this string. If this is nil, the defaults depend on display-time-day-and-date and display-time-24hr-format.

You can customize this variable.

Now, as @lawlist suggested, you can figure out how to set up the string by looking at the docstring for the function format-time-string, although there are too many options to list here. However, you're probably interested in %I, %M, and %S:

...

%H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H only blank-padded, %l is like %I blank-padded.

%p is the locale's equivalent of either AM or PM.

%M is the minute.

%S is the second.

...

So you can either use the customize interface to set display-time-format, or you can do so directly with:

(setq display-time-format "%I:%M:%S")

However, I doubt you're going to be happy with this functionality. From the Emacs manual on mode line basics:

For efficiency, Emacs does not continuously recompute each window's mode line and header line. It does so when circumstances appear to call for it—for instance, if you change the window configuration, switch buffers, narrow or widen the buffer, scroll, or modify the buffer.

In other words, you're not going to get a seconds counter in your mode line. When, after open Emacs with no init file (emacs -Q), I enable display-time-mode and set up the display-time-format as above, the mode-line updates as the seconds turn over to 00 and not every second.

  • 1
    If I understand well, your short answer is that what I have asked for is not possible to be done. By the way there is a missing % in the line (setq display-time-format "%I:%M:S") in your answer. – Name Jan 6 '15 at 8:37
  • 1
    Fixed the typo, thanks. The longer answer was to give you a feel for how you might go about discovering the answer yourself. If you really wanted seconds in your mode line, you would need to force the mode line to update every second. I wouldn't be surprised if there's a way to do that, but it doesn't seem worth the effort. – Dan Jan 6 '15 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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