date is a command-line utility for Unix-like working system to show date and time. Not simply to view, you may as well use the identical command to set system date and time as nicely.
On this article, I’ll present the best way to use the date command within the Linux terminal to show date and time in several methods utilizing a number of examples.
Show Present Date And Time
date command in a console prints the present date and time in a default format string (“+%+”). It reads knowledge from the kernel clock.
Show Date And Time In Person-Outlined Format
For those who don’t just like the default output format “+%+”, you may as well change it and show it in your individual format. What it’s essential do is write your individual format utilizing completely different format controls in a sequence.
$ date "+DATE: %d-%m-%YpercentnTIME: %H:%M:%S %r %ZpercentnDAY: %A"
Listed below are the necessary format controls obtainable to show info:
|%a||Locale’s abbreviated weekday title (e.g., Solar)|
|%A||Locale’s full weekday title (e.g., Sunday)|
|%b||Locale’s abbreviated month title (e.g., Jan)|
|%B||Locale’s full month title (e.g., January)|
|%d||Day of month (e.g., 01)|
|%H||Show hour in 24-hour format|
|%I||Show hour in 12-hour format|
|%p||Locale’s equal of both AM or PM; clean if not recognized|
|%Z||Alphabetic time zone abbreviation (e.g., EDT)|
Show Date And Time Of Completely different Timezone
Like each command-line utility, the date command additionally offers a number of choices to change the output consequence. As an example,
--universal flag can be utilized with date command to print date and time in UTC (Common Time Coordinate or Coordinated Common Time).
$ date -u
Likewise, if you wish to know the date and time of various timezone, you may as well make use of the TZ setting variable with a date. Altering the worth of TZ overrides the default timezone of your system.
$ TZ=America/Chicago date
Wish to know the timezone info? You possibly can run
timedatectl to know your default timezone and
timedatectl list-timezones to listing all obtainable time zones.
Get Previous And Future Date
-d possibility, you may as well show the previous and future dates by giving a date string within the format of a date.
Previous Date And Time
$ date --date="5 years in the past" $ date --date="5 sec in the past" $ date --date="yesterday" $ date --date="5 days in the past"
Future Date And Time
$ date --date="tomorrow" $ date --date="subsequent day" $ date --date="10 day" $ date --date="10 yr"
Get The Final Modified Date Of A File
You too can use the Linux date command to show the date and time of the final modification of a file utilizing
$ date -r <filename>