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!
- [Fix] Linux - bash: useradd: command not found
- Calculate days between dates using dateutils ddiff command
- pwd Command - Print Working Directory
- Rename a directory using Linux/Unix command
- How to go to the End of File in Nano Editor
- How to tar.gz a directory or folder Command
- How to remove/delete a directory in Linux/macOs
- How to Display content of a file in Terminal Screen?
- ls command sort by file size [Linix/UNIX/macOS/bash]
- How to Copy Entire Directory to another Directory in Linux
- 3 ways to clear screen on Linux Terminal
- Command to check Last Login or Reboot History of Users and TTYs
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to backup a file in Linux/Unix
- Command to know the installed Debian version?
- Check SSH/OpenSSH version Command
- 3 Commands to stop Nginx Server
- Linux: Create a New User and Password and Login Example
- How to install npm on Ubuntu
- How to List All Users in Linux
- How to Get the List of Shells on Linux
- Fix - ssh-copy-id no identities found error
- Installing and using unzip Command to unzip a zip file using Terminal
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- zsh hello world example
- How to enable Auto-Save Files in VS Code - HowTos
- Git Remove Untracked Files using Command - Git
- How to Update Microsoft Teams to the latest Version - Teams
- How to know the MAC address of iPhone/iPad Wifi - iOS
- Microsoft Teams: Sign-in is blocked error - Teams
- Multiline EditText in Android Example - Android
- Get List of all local branches git command - Git
- [Fix] Microsoft Store Error Code: 0x803F8001 - Microsoft