How the date command in Linux sets the system time

Source: Internet
Author: User

The first must be the root account.

Name: Date

Use Rights: All users

How to use:

Date [u] [D datestr] [s datestr] [--UTC] [--universal] [--DATE=DATESTR] [--SET=DATESTR] [--help] [--version] [+format] [MMDDHHMM[[CC]YY][.SS]]

Description

Dates can be used to display or set the system's date and time, in the display, the user can set the format to display, format set to a plus after a number of tags, where the list of available tags are as follows:

Time aspect:

%: Printed out%
%n: Next line
%t: Jump Lattice
%H: Hours (00..23)
%I: Hours (01..12)
%k: Hours (0..23)
%l: Hours (1..12)
%m: Min (00..59)
%p: Show local AM or PM
%r: Direct Display time (12-hour system, format hh:mm:ss [ap]m)
%s: Number of seconds from January 1, 1970 00:00:00 UTC to date
%s: sec (00..61)
%T: Direct Display time (24-hour system)
%x: Equivalent to%h:%m:%s
%Z: Show Time zone

Date aspect:
%a: Day of the Week (Sun. Sat)
%A: Day of the Week (Sunday. Saturday)
%b: Month. DEC)
%B: Month (January. December)
%c: Show date and time directly
%d: Day (01..31)
%d: Direct display date (MM/DD/YY)
%h: With%b
%j: The first day of the Year (001..366)
%m: Month (01..12)
%u: The week of the Year (00..53) (with Sunday as the first day of the week)
%w: The first day of the Week (0..6)
%w: The first few weeks of the year (00..53) (in Monday case for day one of the week)
%x: Direct display date (MM/DD/YY)
%y: Last two digits of the year (00.99)
%Y: Full year (0000..9999)

If not with the plus sign as the beginning, it means to set the time, and the time format is MMDDHHMM[[CC]YY][.SS], which MM for the month, DD for the day, HH for the hour, MM for the minute, CC for the year before two digits, YY for the year after two digits, SS for the second number
Parameters:

-D datestr: Displays the time set in DATESTR (non-system time)
--HELP: Display auxiliary messages
-S DATESTR: Set the system time to the time set in Datestr
-U: Show the current Greenwich TIME
--version: Display version number

Example:

Show time after hop, then show current date:
Date ' +%t%n%d '

Show months and Days:
Date ' +%b%d '

Display date and set time (12:34:56):
Date--date ' 12:34:56 '

Attention:

When you don't want meaningless 0 o'clock (for example, 1999/03/07), you can insert a symbol in the tag, such as Date ' +%-h:%-m:%-s ' to remove the meaningless 0 from the minute, as if the original 08:09:04 would become 8:9:4. In addition, only those who get permission (for example, root) can set the system time.

When you change the system time as root, remember to write the system time to the CMOS in Clock-w, so that the system time will continue to hold the latest correct value the next time you reboot.

Example: Modification Date Time

At the command line, enter:

Date

Show Current Time Fri Aug 3 14:15:16 CST 2007

Date-s

Modify Time by string

Can only modify the date, do not modify the time, input: Date-s 2007-08-03
Only modify time, enter: Date-s 14:15:00
Also modify the date time, note to add double quotes, between the date and time a space, enter: Date-s "2007-08-03 14:15:00"

When you have finished modifying, remember to enter: Clock-w

Writes the system time to the CMOS

Set the time to 14:36 P.M..

# date-s 14:36:00

Fri Nov 14:15:00 CST 1999

Set the time to November 28, 1999.

# date-s 991128

Sun Nov 00:00:00 CST 1999


Suppose you want to set the time is January 3, 2008 18:24

Method One:

Date 010318242008 (days of the Month) (full written)

Method Two:

1 Set the date first
Date-s 20080103
2 "Set time
Date-s 18:24
+++++++++++++++++++++++++++++
If you want to change the BIOS time at the same time
In the implementation
Clock-w

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.