Linux command set time

1、date:

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

Description: The system can be used to set the date and time. Only administrators have the authority to set the date and time, the average user can only display the time with the date command. Without any arguments, data shows the current date and time.

Example 1 : Show the current time

[root@Test2 ~]# date                                                                  

June 17, 2010 00:00:04 CST Thursday

Example 2 : Set the date and time for the 2010 Nian 6 Yue 18 Hao 12:00

[root@Test2 ~]# date -s "20100618 12:00:00"

June 18, 2010 12:00:00 CST Friday

Example 3 : Set the date for the 2010 years of 6 Yue 18 Hao

[root@Test2 ~]# date -s 20100618

June 18, 2010 00:00:00 CST Friday

Example 4 : Set time 12:00:00

[root@Test2 ~]# date 12:00:00

date: invalid date “12:00:00”

Example 5 : Display time zone

[root@Test2 ~]# date -R

Thu, 17 Jun 2010 00:01:36 +0800

or:

[root@Test2 ~]# cat /etc/sysconfig/clock

# The ZONE parameter is only evaluated by system-config-date.

# The timezone of the system is defined by the contents of /etc/localtime.

ZONE="Asia/Shanghai"

UTC=true

ARC=false

2、hwclock/clock

Syntax: hwclock [--adjust] [- debug] [- directisa] [- hctosys] [- show] [- systohc] [- test]

[--Utc] [- version] [- set --date = <date and time>]

parameter:

When --adjust hwclock each time you change the hardware clock, it will be recorded in / etc / adjtime file. --Adjust use parameter can be estimated deviation hwclock hardware clock based on the previous recording, and for correcting the current hardware clock.

When hwclock --debug display detailed execution information.

--directisa hwclock preset from / dev / rtc device to access the hardware clock. If not accessible, this parameter can be used directly in the I / O instructions to access the hardware clock.

--hctosys the system clock is adjusted to be consistent with the current hardware clock.

--set --date = <date and time> setting the hardware clock.

--show time and date display hardware clock.

--systohc the hardware clock is adjusted to be consistent with the current system clock.

--test only test program, but does not actually change the hardware clock.

--utc To use Greenwich Mean Time, add this parameter, hwclock will perform the work of conversion.

--version display version information.

Example 1 : View hardware time

# hwclock --show

or

# clock --show

Example 2 : Set Time Hardware

# Hwclock --set --date = "07/07/06 10:19" (month / day / year hours: minutes: seconds)

or

# Clock --set --date = "07/07/06 10:19" (month / day / year hours: minutes: seconds)

Three cases : the synchronization of the hardware and system time

According to the previous statement, restart the system, the hardware will read the system time to time, synchronization, but when not restart, the need to achieve synchronization with a clock or hwclock command.

Hardware clock and system clock synchronization:

# Hwclock --hctosys (hc hardware on behalf of the time, sys represents the system time)

or

# clock –hctosys

Example 4 : system clock and hardware clock synchronization:

# hwclock --systohc

or

# clock –systohc

Example 5 : Forced writes the CMOS system time , so that permanent, to avoid restored to the original time after system reboot

# clock –w

or

# hwclock -w

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11108749.html