Date command and system time setting in CentOS

Source: Internet
Author: User
Tags current greenwich mean time

Date command and system time setting in CentOS
Linux Clock is divided into System Clock and Real Time Clock (RTC. The system clock is the current Linux Kernel clock, and the hardware clock is the battery-powered clock on the motherboard. This hardware clock can be set in the BIOS. When Linux is started, the hardware clock reads the system clock settings, and then the system clock runs independently of the hardware. All commands (including functions) in Linux use the system clock settings. In Linux, the commands used for clock viewing and setting mainly include date and hwclock.
1. date
Name: date
Permission: All Users
Usage:
Date [-u] [-d datestr] [-s datestr] [-- utc] [-- universal] [-- date = datestr] [-- set = datestr] [-- help] [-- version] [+ FORMAT] [MMDDhhmm [[CC] YY] [. ss]
Note:
Date can be used to display or set the date and time of the system. In terms of display, you can set the format to be displayed. The format is set to a plus sign followed by several tags, the available tags are listed as follows:
Time:
%: Print %
% N: Next row
% T: Skip
% H: hour (00-23)
% I: hour (01-12)
% K: hour (0-23)
% L: hour (1-12)
% M: minute (00-59)
% P: displays local AM or PM
% R: direct display time (in 12-hour format: hh: mm: ss [AP] M)
% S: the number of seconds since January 1, 1970 00:00:00 UTC till now
% S: seconds (00-60)
% T: direct display time (in 24-hour format)
% X: equivalent to % H: % M: % S
% Z: display the time zone
Date:
% A: The day of the week (Sun-Sat)
% A: The day of the week (Sunday-Saturday)
% B: Month (Jan-Dec)
% B: Month (January-December)
% C: Display date and time directly
% D: Day (01-31)
% D: Display date directly (mm/dd/yy)
% H: Same as % B
% J: The day of the year (001-366)
% M: Month (01-12)
% U: Week (00-53) of the year (the first day of the week on Sunday)
% W: The day of the week (0-6)
% W: Week (00-53) of the Year (Monday is the first day of the week)
% X: Display date directly (mm/dd/yy)
% Y: last two digits of the Year (00.99)
% Y: full year (0000-9999)
If it does not start with a plus sign, the time is set, 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 second digit of the Year, ss is the second digit
Parameters:
-D datestr: display the time set in datestr (non-system time)
-- Help: displays auxiliary messages.
-S datestr: set the system time to the time set in datestr
-U: displays the current Greenwich Mean Time.
-- Version: displays the version number.
Example:
After the display time, skip the line and then
Display current date: # date '+ % T % n % d'
Show month and number of days: date' + % B % d'
Display date and set time (12:34:56): # date -- date '12: 34: 56'
Note: If you do not want meaningless 0 values (for example,), you can insert the-symbol in the tag, for example, date '+ %-H: %-M: %-S will remove the meaningless 0 in the hour, minute, and second, as if the original 08:09:04 will change. In addition, you can set the system time only when you have the permission (such as root.
After you change the system time as root, remember to write the system time to CMOS using clock-w, in this way, the system time will continue to hold the latest correct value upon the next reboot.
Example: Modify the date and time
On the command line, enter:
Date: displays the current time Fri Aug 3 14:15:16 CST 2007
Date-s: Time modified in string Mode
You can modify only the date without changing the time. Enter: date-s
Modify the time only. Enter date-s 14:15:00.
Modify the date and time at the same time. Add double quotation marks. There is a space between the date and time. Enter:
# Date-s "14:15:00"
2. View hardware time
# Hwclock
Set hardware time
# Hwclock-set-date = "07/07/06" (month/day/year hour: minute: second)
3. Hardware time and System Time Synchronization
As mentioned above, when the system is restarted, the hardware time will read the system time for synchronization. However, when the system is not restarted, you need to use the hwclock command for synchronization.
Hardware clock and system clock synchronization:
# Hwclock -- hctosys (hc indicates the hardware time, sys indicates the system time)
System clock and hardware clock synchronization: (synchronize the system time to the hardware clock)
# Hwclock-systohc

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.