查看下当前时间
A-bcd:/ # date
Mon Dec 12 16:51:49 GMT 2022
A-bcd:/ #
设置2021-01-30 16:01:30
A-bcd:/ # date 013016012021.30
Sat Jan 30 16:01:30 GMT 2021
A-bcd:/ # date
Sat Jan 30 16:01:34 GMT 2021
A-bcd:/ #
设置2021-02-01 17:30:55
A-bcd:/ # date 0201173021.55
Mon Feb 1 17:30:55 GMT 2021
A-bcd:/ #
设置1981-10-01 12:36:55
A-bcd:/ # date 100112361981.55
Thu Oct 1 12:36:55 GMT 1981
A-bcd:/ #
设置1997-02-01 11:30:55
A-bcd:/ # date 0201113097.55
Sat Feb 1 11:30:55 GMT 1997
A-bcd:/ #
为什么这么用呢?查看date --help,同时也证明如果help下没有【-s】参数可用,你就不能用【date -s XXXX】这个命令
说明一下【Default SET format is "MMDDhhmm[[CC]YY][.ss]", that's (2 digits each)】中的CC和YY,说明年也可以4个数字设置,也可以2个数字设置,见上面例子。
特别特别注意:date设置必须有root权限,切记切记!
A-bcd:/ # date --help
usage: date [-u] [-r FILE] [-d DATE] [+DISPLAY_FORMAT] [-D SET_FORMAT] [SET]
Set/get the current date/time. With no SET shows the current date.
Default SET format is "MMDDhhmm[[CC]YY][.ss]", that's (2 digits each)
month, day, hour (0-23), and minute. Optionally century, year, and second.
Also accepts "@UNIXTIME[.FRACTION]" as seconds since midnight Jan 1 1970.
-d Show DATE instead of current time (convert date format)
-D +FORMAT for SET or -d (instead of MMDDhhmm[[CC]YY][.ss])
-r Use modification time of FILE instead of current date
-u Use UTC instead of current timezone
+FORMAT specifies display format string using strftime(3) syntax:
%% literal % %n newline %t tab
%S seconds (00-60) %M minute (00-59) %m month (01-12)
%H hour (0-23) %I hour (01-12) %p AM/PM
%y short year (00-99) %Y year %C century
%a short weekday name %A weekday name %u day of week (1-7, 1=mon)
%b short month name %B month name %Z timezone name
%j day of year (001-366) %d day of month (01-31) %e day of month ( 1-31)
%N nanosec (output only)
%U Week of year (0-53 start sunday) %W Week of year (0-53 start monday)
%V Week of year (1-53 start monday, week < 4 days not part of this year)
%D = "%m/%d/%y" %r = "%I : %M : %S %p" %T = "%H:%M:%S" %h = "%b"
%x locale date %X locale time %c locale date/time
A-bcd:/ #