Skip to main content

Command Palette

Search for a command to run...

Show Time and Date in the Terminal

Show time and date in the terminal. You can show the time and date on the right side of the terminal. You should have a ZSH shell and oh-my-zsh to use this.

Updated
1 min read
Show Time and Date in the Terminal
J

Shezan loves technology who is currently studying Computer Science and Engineering. He codes frontend & backend of a website. He also does penetration testing on web apps.

Show time and date in the terminal. You can show the time and date on the right side of the terminal. You should have a ZSH shell and oh-my-zsh to use this.

Add this into ~/.zshrc above source ~/.zshrc line for ZSH shell to show time & date on the right side of the terminal.

RPROMPT='${ret_status}%{$fg[green]%}~ %{$fg_bold[black]%}$(git_prompt_info)%{$bg[yellow]%}%{$fg[black]%} %D{%a, %f %b %Y} %{$bg[red]%}%{$fg[white]%}%D{ %L:%M:%S %p} % %{$reset_color%}'

Image preview:

only-time-and-date

Full image:

full

[Note: I am using Kali Linux with oh-my-zsh (agnoster theme) on ZSH shell in Windows Terminal WSL.]

You can change all the colors shown in the picture. change them in bg and fg. bg = background, fg = foreground .

See more about supported color

You can edit time and date format by changing them after %D .
Some Time format:

 %D     The date in yy-mm-dd format.
 %T     Current time of day, in 24-hour format.
 %t %@  Current time of day, in 12-hour, am/pm format.
 %*     Current time of day in 24-hour format, with seconds.
 %w     The date in day-dd format.
 %W     The date in mm/dd/yy format.
 %D{strftime-format}

See More about Time format

If you want this on left side, then just write PROMPT instead of RPROMPT .

Linux

Part 2 of 7

Dive into the world of Linux with our Hashnode series! From tutorials to tips and tricks, unlock the power of open-source OS in every article.

Up next

Installing Zen Browser on Linux: Download, Setup, and Create a Desktop Entry

Your Step-by-Step Guide to Installing Zen Browser on Linux with a Desktop Shortcut for Effortless Access