date - command can be used in Linux/Unix/macOS Terminal to display or set date and time. You can use the date command with various arguments to display date in various formats and timezones as well as manipulate the date and time.
Let's see examples of how you can use date commands with some examples,
Syntax: date [argument(s)] [+Format(s)]
1. Example: date
Let's first use the simple command date, you will see that the default output you get is in format (day of the week, month, date, hour:minute:seconds TimeZone Year)
$ date
Sat Jun 26 23:09:15 CDT 2021
2. Example: date -u
If you use the option -u along with the date command, you will see that the outputted date time is in UTC timezone.
$ date -u
Sun Jun 27 05:55:11 UTC 2021
3. Example: Displaying date/time in various formats
You make make use of the below date format options to output the date and time in various formats as you want,
Date Format Option | Command | Output | Usage |
---|---|---|---|
%a | data +"%a" | Sun | Displays day of the weak in short form i.e. Sun, Mon, Tue, Wed, Thu, Fri, Sat. |
%A | data +"%A" | Sunday | Displays day of the week in long form i.e. Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday. |
%b | date +"%b" | Jun | Displays the current month in short form i.e. Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec. |
%B | data +"%B" | June | Displays the current month in long form i.e. January, February, March, April, May, June, July, August, September, October, November, December. |
%d | data +"%d" | 27 | Displays day of the month in numeric format. |
%Y | data +"%Y" | 2021 | Displays the current year in format yyyy. |
%D | data +"%D" | 06/27/2021 | Displays the current date in MM/dd/yyyy format. |
%H | data +"%H" | 09 | Displays the current hour in HH format (01-23) |
%m | data +"%m" | 06 | Displays the current month in MM format: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12. |
%I | data +"I" | 11 | Displays the current hour 01-11 format. |
%M | data +"M" | 51 | Displays the current minutes in mm format: (00-59) |
%S | data +"%S" | 25 | Displays the current seconds: (00-59) |
Let's see some examples with using the date/time format string in conjunction.
Example: Display date in dd-MM-yyyy format$ date +"%d-%m-%Y"
27-06-2021
Example: Display date in yyyy-MM-dd format
$ date +"%Y-%m-%d"
2021-06-27
Example: Display date in MM-dd-yyyy format
$ date +"%m-%d-%Y"
06-27-2021
Example: Display date in dd-MM-yy format
$ date +"%d-%m-%y"
27-06-21
Example: Display date in MM/dd/yy format
$ date +"%m/%d/%y"
06/27/21
Example: Display date in dd/MM/yyyy format
$ date +"%m/%d/%Y"
27/06/2021
Example: Display date in dd-MMM-yyyy format
$ date +"%d-b%-%Y"
27-Jun-2021
Example: Display date and time: dd-MM-yyyy HH:mm:ss format
$ date +"%d-%m-%Y %I:%M:%S"
27-06-2021 12:28:52
Example: Display time in HH:mm format
$ date +"%I:%M"
12:28

4. Example: Displaying date/time in epoch time
In order to display the date in Epoch time you can use of the format string %s
$ date %s
1624777451
Have Questions? Post them here!
- Rename a directory using Linux/Unix command
- ls command to list only directories
- How to Restart or Reload Nginx Server Service on Linux
- 3 ways to clear screen on Linux Terminal
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: sudo: unable to open Read-only file system
- Create Hidden File or Directory using Shell Command
- Command to know the installed Debian version?
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - bash: man: command not found
- How to tar.gz a directory or folder Command
- How to Display content of a file in Terminal Screen?
- How to change bash terminal prompt string and color
- Sort ls command by last modified date and time
- Execute .bin and .run file Ubuntu Linux
- zsh hello world example
- How to check uptime of Linux/Unix/macOS system/server using console command?
- [Fix] Linux - bash: useradd: command not found
- Command to check Last Login or Reboot History of Users and TTYs
- How to install and Configure sar sysstat tools in Ubuntu Linux
- How to use SCP Command to Copy Directory
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to connect to SSH port other than default 22
- Install OpenSSL on Linux/Ubuntu
- Python: Traverse List Backwards - Python
- How to Restart Mac using Terminal Command - MacOS
- 5 Ways to Loop a Dictionary in Python - Python
- Java: Convert Stream to List - Java
- Change the background of Tkinter label or text - Python
- How to get file path in Idea IntelliJ IDE - Java
- Jupyter Notebook add Table Of Contents (TOC) - Python
- List of PowerShell Cmdlet Commands for Mac - Powershell