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!
- How to remove/delete a directory in Linux/macOs
- What does apt-get update command does?
- How to quit or exit SFTP Prompt on Terminal
- How to exit from nano command
- Rename a directory using Linux/Unix command
- Calculate days between dates using dateutils ddiff command
- 3 Commands to stop Nginx Server
- How to use SCP Command to Copy Directory
- bash: cls: command not found
- How to Install CVS Version Control on Linux/Ubuntu
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- [Ubuntu] Search a package and versions using apt command
- zsh hello world example
- SCP Copy all files from directory to Local Folder
- Create Hidden File or Directory using Shell Command
- Check SSH/OpenSSH version Command
- How to install python pip on Ubuntu using apt command
- How to remove or uninstall Java from Ubuntu using apt-get
- How to change bash terminal prompt string and color
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- ls command sort by file size [Linix/UNIX/macOS/bash]
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- How to tar.gz a directory/folder
- Terminal display next month Calendar
- 3 ways to clear screen on Linux Terminal
- How to remove Siri from Menu Bar [macOS Big Sur] - MacOS
- How to fix Microsoft Windows 10 update error 80070020 - Microsoft
- Bootstrap Nav Menu Dropdown on hover - Bootstrap
- Android Parsing Data for android-L failed Unsupported major.minor version 51.0 Error - Android
- How to open a new tab in Notepad++ - NotepadPlusPlus
- Notepad++ Editor alternatives for Mac OS X - NotepadPlusPlus
- Create SharePoint Site Collection with new Content database in existing web application - SharePoint
- Change Height of Android ActionBar - Android