Home  >  Article  >  Operation and Maintenance  >  What is the command to modify the system time in Linux?

What is the command to modify the system time in Linux?

WBOY
WBOYOriginal
2021-12-24 13:41:3022745browse

The Linux command to modify the system time is "date". The function of the date command is to display or set the system date and time. The format is set to a plus sign followed by several marks. Different marks display differently. The time format, the syntax is "date 'time stamp'".

What is the command to modify the system time in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is the Linux command to modify the system time

The Linux date command can be used to display or set the system date and time. In terms of time, the user can set the format to be displayed. The format is set to a plus sign followed by several marks. The list of available marks is as follows:

Time:

  • %: Print %

  • %n: Next line

  • ##%t: Tab

  • %H : Hour(00..23)

  • %I : Hour(01..12)

  • %k : hour(0..23)

  • %l : hour(1..12)

  • %M : minute(00.. 59)

  • %p: Display local AM or PM

  • ##%r: Display time directly (12-hour format, format is hh:mm :ss [AP]M)
  • %s : Number of seconds since January 1, 1970 00:00:00 UTC
  • %S: Seconds (00..61)
  • %T: Display time directly (24-hour format)
  • %X : Equivalent to %H:%M:%S
  • ##%Z : Display time zone
  • Date aspect:

%a: Day of the week (Sun..Sat)
  • %A: Day of the week (Sunday..Saturday)
  • %b: Month (Jan..Dec)
  • ##%B: Month (January..December)

  • ##%c: Direct display Date and time

  • %d: Day (01..31)

  • %D: Directly display date (mm/dd/yy)

  • %h: Same as %b

  • ##%j: Day of the year (001..366)
  • %m: month (01..12)
  • %U: week of the year (00..53) (Sunday is the week) The first day of the week)
  • %w: The day of the week (0..6)
  • %W: One The number of the week in the year (00..53) (Monday is the first day of the week)
  • ##%x: Display the date directly (mm/dd/yy)
  • %y: The last two digits of the year (00.99)
  • ##%Y: The complete year (0000..9999)

  • If it does not start with a plus sign, it means that the time needs to be set, and the time format is MMDDhhmm[[CC]YY][.ss], where MM is the month, DD is the day, and hh is Hour, mm is the minute, CC is the first two digits of the year, YY is the last two digits of the year, ss is the second.

  • Usage permissions: all users.
  • When you don't want meaningless 0s to appear (for example, 1999/03/07), you can insert the - symbol in the mark, such as date ' %-H:%-M:%-S ' will remove the meaningless 0s in hours, minutes and seconds. For example, the original 08:09:04 will become 8:9:4. In addition, only those with permission (such as root) can set the system time.

  • After you change the system time as root, please remember to use clock -w to write the system time to CMOS, so that the system time will continue to hold the latest correct value the next time you reboot.

The syntax is:

date [-u] [-d datestr] [-s datestr] [--utc] [--universal] [--date=datestr] [--set=datestr] [--help] [--version] [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]

Among them:

-d datestr: Display the time set in datestr (non-system time)

--help: Display auxiliary information


-s datestr: Set the system time to the time set in datestr

-u: Display the current Greenwich Mean Time

--version: Display version number

Related recommendations: "

Linux Video Tutorial

"

The above is the detailed content of What is the command to modify the system time in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn