8

I usually use Spacemacs in maximized window, thus the date and time presented in mode line is a must.

I understand that spacemacs uses powerline mode to mimic vim, the manuals of both spacemacs and powerline does not tell how to add new section to display additional info (in this case it is date and time).

I have attempted to comprehend the nyan cat code in color layer, but my elisp skill did not satisfy.

9

To get the time mode, just add (display-time-mode 1) to your ~/.spacemacs configuration.

To get date and time, do this instead

;;display time in powerline
  (spacemacs|define-mode-line-segment date-time-segment
    (shell-command-to-string "echo -n $(date +%k:%M--%m-%d)")
    )
  (add-to-list 'spacemacs-mode-line-right 'date-time-segment)

Source: https://www.reddit.com/r/emacs/comments/3lu414/how_to_add_date_and_time_into_spacemacs_powerline/

I customized mine with this...

  ;; display time in powerline
  (spacemacs|define-mode-line-segment date-time-segment
    (shell-command-to-string "echo -n \"⏰  $(date '+%a %d %b %I:%M%p')\""))
  (add-to-list 'spacemacs-mode-line-right 'date-time-segment)
  )

so now my powerline looks like this

my_power_line

| improve this answer | |
  • As far as I can tell, this solution is out of date. See my answer for what worked for me. – Dave Parrish Feb 25 '18 at 17:56
2

What worked for me was the following.

(spaceline-define-segment datetime
  (shell-command-to-string "echo -n $(date '+%a %d %b %I:%M%p')"))
(spaceline-spacemacs-theme 'datetime)

I had to put that code in user-config section of .spacemacs.

| improve this answer | |
1

Mine's working great just with:

(setq display-time-format "%H:%M:%S %a,%d %b %Y")

(display-time)                 
| improve this answer | |
  • Welcome to Emacs.SE! Could you please elaborate on what, if anything, the OP has to do to incorporate your code into his spacemacs configuration. It would also help if you could explain how your answer differs from the others already posted. – Dan Mar 25 at 15:26
0

Emacs has native time functions: current-time-string and format-time-string. You should just have to eval one of those - i.e. (current-time-string). This works fine for telephone line, so I would assume it's the same for powerline/spaceline/etc.

E.g.

(spaceline-define-segment datetime
  (current-time-string))
(spaceline-spacemacs-theme 'datetime)

Here's the doc for format-time-string if you want something other than the default:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Time-Parsing.html

| improve this answer | |

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.