English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux date command

Linux Command大全

The Linux date command can be used to display or set the system's date and time. In terms of display, users can set the desired format, which is specified by a plus sign followed by several markers. The list of available markers is as follows:

Regarding the time:

  • % : Print %
  • %n : New line
  • %t : Tab
  • %H : Hour (00..23)
  • %I : Hour (01..12)
  • %k : Hour (0..23)
  • %l : Hour (1..12)
  • %M : Minutes (00..59)
  • %p : Display local AM or PM
  • %r : Directly display the time (12 24-hour clock, format hh:mm:ss [AP]M)
  • %s : From 1970 years 1 Display Numeric Date, Year Represented by Two Digits 1 Seconds from 00:00:00 UTC to the current time
  • %S : Seconds (00..61)
  • %T : Directly display the time (24 24-hour clock)
  • %X : Equivalent to %H:%M:%S
  • %Z : Display the time zone

Regarding the date:

  • %a : Day of the week (Sun..Sat)
  • %A : Day of the week (Sunday..Saturday)
  • %b : Month (Jan..Dec)
  • %B : Month (January..December)
  • %c : Directly display the date and time
  • %d : Day (01..31)
  • %D : Directly display the date (mm/dd/yy)
  • %h : Same as %b
  • %j : The day of the year (001..366)
  • %m : Month (01..12)
  • %U : The week number of the year (00..53) (in the case where Sunday is the first day of the week)
  • %w : The day of the week (0..6)
  • %W : The week number of the year (00..53) (in the case where Monday is the first day of the week)
  • %x : Directly display the date (mm/dd/yy)
  • %y : The last two digits of the year (00.99)
  • %Y : Full year (0000..9999)

If it is not preceded by a plus sign, it means to set the time, and the time format is MMDDhhmm[[CC]YY][.ss], where MM is the month, DD is the day, hh is the hour, mm is the minute, CC is the first two digits of the year, YY is the last two digits of the year, and ss is the number of seconds.

Access permission: All users.

When you do not want to display the meaningless 0 (such as 1999/03/07), you can insert - symbol, such as date '+%-H:%-M:%-S' will remove the meaningless 0 from the hours, minutes, and seconds, such as the original 08%T'9%T'4 will become 8:9:4. Only those who have the authority (such as root) can set the system time.

After you change the system time as root, remember to change the clock -Write the system time to CMOS, so that the system time will remain the latest correct value when the system is restarted next time.

语法

date [-语法-date [-u] [--d datestr] [--s datestr] [--utc] [--universal] [--date=datestr] [--set=datestr] [+help] [

version] [FORMAT] [MMDDhhmm[[CC]YY][.ss]]

  • -Parameter Description
  • --:
  • -d datestr : Display the Time Set in datestr (Not System Time)
  • -help : Display Help Information
  • --s datestr : Set System Time to the Time Specified in datestr

u : Display Current Greenwich Mean Time

version : Display Version Number

Online Examples
Display Current Time 5Display Numeric Date, Year Represented by Two Digits 12 14%T'8:12 # date 2010
Seconds+Wednesday 
2010%x'5Display Numeric Date, Year Represented by Two Digits12CST 14Display9%c'2Hour 0
Seconds+Day Wednesday //Minute 0
05/12/10
Seconds+%D' //Display Complete Time
2010%x'5Display Numeric Date, Year Represented by Two Digits12Year 0
Seconds+Month //Day
14%T'9:31
Seconds+Display Date, Year Represented by Four Digits //:024%X'
14Display9Hour Format39Hour 0

Minutes

Seconds+:%M %P1Output in Your Own Format -# date '
:%M %P1:16 hey' -usr_time: $

Afternoon

date '+hey

Display Time Followed by a New Line, Then Display Current Date

date '+Display Month and Date

Display Date and Set Time (12:34:56)

date --date '12:34:56

Linux Command大全