7

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.

Aaron Hall
  • 419
  • 1
  • 6
  • 20
Xi Xiao
  • 523
  • 4
  • 11

4 Answers4

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

Jeff
  • 211
  • 1
  • 5
  • 1
    As far as I can tell, this solution is out of date. See my answer for what worked for me. – Dave Feb 25 '18 at 17:56
3

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.

Dave
  • 131
  • 2
2

Mine's working great just with:

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

(display-time)                 
Waldemar22
  • 71
  • 5
  • 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 '20 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

Stefan
  • 26,154
  • 3
  • 46
  • 84