Date — The Command
“Exploring date commands in Linux Operating System!”
Technically, date command is used to display the system’s date and time. By default the date command displays the date in the time zone on which unix/linux operating system is configured.
There are a lot of ways of customizing the output of date command, presenting in a variety of formats, calculating dates as well as setting the system clock with admin rights.
- date command:- The simple date command will show you the current date and time of the system.
- man date command:- Basically, man command or manual command is a built-in manual for using Linux commands It allows users to view the reference manuals of a command or utility run in the terminal.
These are the most common formatting characters for the date
command:
%D
– Display date as mm/dd/yy%Y
– Year (e.g., 2020)%m
– Month (01-12)%B
– Long month name (e.g., November)%b
– Short month name (e.g., Nov)%d
– Day of month (e.g., 01)%j
– Day of year (001-366)%u
– Day of week (1-7)%A
– Full weekday name (e.g., Friday)%a
– Short weekday name (e.g., Fri)%H
– Hour (00-23)%I
– Hour (01-12)%M
– Minute (00-59)%S
– Second (00-60)
Set or Change Date in Linux
To change the system clock manually, use the --set
command. For example, to set the date and time to 5:30 PM, May 13, 2010, type:
date --set="20100513 05:30"
Display Past Dates
Use the --date
option to display past dates in Linux. The date
command accepts values such as "tomorrow"
, "Friday"
, "last Friday"
, "next Friday"
, "next week"
, and similar. So, use the following strings to print past dates::
date --date="2 year ago"
Display Future Dates
The --date
option can also display future dates. Like with past dates, you can type in strings to print upcoming dates:
date --date="next monday"
Override a Time Zone
By default, the date
command uses the time zone defined in /etc/localtime
. To use a different time zone in the environment, set the TZ
variable to the desired time zone.
For example, to switch to New York time, enter:
TZ='America/New_York' date
and there are several topics in date command ,
keep learning and exploring ..!!
Thank you.!!