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.

These are the most common formatting characters for the date command:

  • %D – Display date as mm/dd/yy

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.!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store