Date, time, and timezone are very important for IT systems. This information is used to provide information about log time, operation time, etc. The date is related to the day, weekday, month, yea, etc. Time is related to the hour, minute, second, etc. Timezone is the difference between current location time from the GMT.
Print Current Date and Time
Before settings the date and time displaying them is very useful .This can prevent errors and used to check if the current date and time is correct. The date command is used to print both date and time information for the Linux system.
date
The date command output is like below where day name, day, month, year, hour, minute, seconds and timezone information is printed.
Çrş 17 Mar 2021 18:36:47 +03
Print Only Current Date
Only the date can be printed by using the format specifiers. The year is expressed with %Y, the month is expressed with %m, and the day is expressed with the %d.
date +%Y-%m-%d
2021-03-17
Print Only Current Time
Only time can be printed by using the date command with the %H and %m format specifiers. The %H is used to show hour and %m is used to show minute.
date +%H:%m
18:03
Print Timezone
The date command can be also used to print only timezone of the Linux system. The %z is used to print time zone.
date +%z
+0300
The + sign means before the GMT 03 is for hours and last 00 is for minutes. Simply current time zone is before the GMT.
Set Date
The date command can be also used to set date information for the current Linux system. In order to set date the -s option can be used with the date value.
date +%Y%m%d -s "20210317"
Set Time
The time information can be also set by using the -s and +%T options. The time value is specified as “11:20:30”.
date +%T -s "11:20:30"