Time management commands date, clock, and hwclock

Source: Internet
Author: User

Date: Date


1. Command function:

To display or set the system time and date, note that only super users can use the date command to set the time. Generally, users can only use the date command to display the time.


2. Usage:

Date [Options] [+ format]


3. parameter description:

-D <string>: displays the date and time specified by the string. Double quotation marks must be added before and after the string.

-S <string>: Specifies the date and time based on the string. Double quotation marks must be added before and after the string.

-U: displays GMT.

% Y year (in the format of 00-99 ).

% Y year (in four digits ).

% M month (expressed as 01-12 ).

% D Date (expressed in 01-31 ).

% D Date (including year, month, and day ).

% H (expressed in-23 ).

% M minutes (expressed in-59 ).

% S seconds (expressed in local usage ).

% T time (including hour, minute, and second, expressed in 24 hours ).


4. Example:


[[Email protected] ~] # Date // Date and Time

Sat Oct 19:36:16 CST 2016


[[Email protected] ~] # Date + % d // year, month, and day

10/15/16


[[Email protected] ~] # Date + % t // hour, minute, and second

19:37:07


[[Email protected] ~] # Date + % Y // four-digit year

2016


[[Email protected] ~] # Date + % Y // two-digit year

16


[[Email protected] ~] # Date + % m // month

10


[[Email protected] ~] # Date + % d // day

15


[[Email protected] ~] # Date + % H // hour (in 24-hour format)

19


[[Email protected] ~] # Date + % m // minute

41


[[Email protected] ~] # Date + % S // second

55


[[Email protected] ~] # Date + "Today is % Y/% m/% d ."

Today is 2016/10/15.


[[Email protected] ~] # Date + "The time now is % H: % m: % S ."

The time now is 19:56:44.


[[Email protected] ~] # Date-s 2016-10-19 // modify the system date

Wed Oct 19 00:00:00 CST 2016


[[Email protected] ~] # Date-s 20:38:44 // modify the system time

Wed Oct 19 20:38:44 CST 2016


[[Email protected] ~] # Date-s "20:37:44" // modify the system date and time at the same time

Sat Oct 20:37:44 CST 2016


Clock: Clock


1. Command function:

Display or set hardware time and date


2. Usage:

Clock [Options] [+ format]


3. parameter description:

-R: -- show read and print the hardware clock (read hardware clock and print result)
-S: -- hctosys synchronize the hardware clock to the system clock (set the system time from the hardware clock)
-W: -- systohc synchronize the system clock to the hardware clock (set the hardware clock to the current system time)


4. Example:


[[Email protected] ~] # Clock-R

Sat Oct 15 20:34:13 2016-1.047927 seconds


Hwcloc and clock are the same commands.

The relationship between system time and CMOS time. The system time is maintained by the Linux operating system, and the CMOS time is the time when the CMOS chip is saved. When the system starts, the operating system records the read time from CMOS as the system time, and the operating system automatically writes the system time to CMOS at intervals of time. If you use the date command to change the system time and restart the computer immediately, the operating system has not synchronized the system time to CMOS, so there is still no pre-modification time after the boot, so for the sake of security, you can also manually use the clock command to synchronize the system time to CMOS.



Time management commands date, clock, and hwclock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.