8.7 "Linux learning is not difficult" Linux Common Operations Command (7): Date command to display or set the system day and time
use the date command to display and set the dates and times of a computer system. Only Superuser has permission to use the date command to set
date and time, and the average user can only display the date and time using the date command.
command syntax:
Date [ options ] [ Show time format ]
The meanings of the options in the command are as shown in the table.
Options |
option meaning |
-D < string > |
displays the time described by the specified string, not the current time |
-S < strings > |
set the specified string to separate time |
when displaying datetime, you can use the time domain, which is the meaning of the time domain as shown in the table.
Time Domain |
time domain meaning |
%a |
abbreviation of the week name |
%A |
Full name of the week |
%b |
abbreviation for month name |
%B |
Full name of month |
%c |
Date and Time |
%c |
century, usually to omit the last two digits of the current year |
%d |
date by month (from~to) |
%d |
Date (mm/dd/yy) |
%e |
date by month, add a space, equal to %_d |
%F |
Full date format , equivalent to %y-%m-%d |
%g |
last two bits of the ISO-8601 format year |
%G |
ISO-8601 format year, generally only used in conjunction with%V |
%h |
Same as the %b. |
%H |
hours (xx~) |
%I |
hours (~) |
%j |
the first day of the year (001~366) |
%k |
hours (0~+) |
%l |
hours (1~) |
%m |
month (~) |
%M |
points (xx~) |
%N |
nanoseconds (000000000-999999999) |
%p |
show the morning or afternoon |
%P |
similar to%p, but with output lowercase letters |
%r |
time, hour system |
%R |
Time and minute of the hour, equivalent to %h:%m |
%s |
from 1970 years 1 months 1 days 0 points to the current experience of the number of seconds |
%s |
seconds (xx~) |
%T |
time ( hour system) (hh:mm:ss) |
%u |
Week,1 stands for Monday |
%u |
Week of the year, with Sunday as the first day of each week |
%V |
ISO-8601 Format Specification for the week of the year, with Monday as the first day of the week (01-53) |
%w |
Day of the week one (0 for Sunday) |
%W |
the first few weeks of the year (fromxxto Monday |
%x |
format of the display date |
%x |
format of display time (% H time%M min%S s) |
%y |
the last two digits of the year (1999 is the first) |
%Y |
year (e.g. 1970,1996, etc.) |
%Z |
time zone abbreviations by alphabetical order |
Example: Displays the date and time on the current computer system.
[[Email protected] ~]# Date December 23, 2015 Wednesday 06:00:50 CST
Example: Displays the computer date and time in the specified format.
[[Email protected] ~]# date + '%r%a%d%h%y ' 07:14 P.M. 14 sec 3,022 Month 28
Example: Set the computer time to 9 points in the morning .
[[email protected] ~]# date-s 09:16:00 February 02, 2028 Wed 09:16:00 CST
Example: Setting the computer time is 2024 year 4 month Day.
[[email protected] ~]# date-s 240414 April 14, 2024 Sunday 00:00:00 CST
This article extracts from "Linux Learning is not difficult" textbook, which is one of the most practical, theoretical and practical Linux Introductory materials. To read the entire book, visit the Linux ops (www.linuxywz.com) website .
Linux Common Operations Command (7): Date command to display or set system dates and times