Date +%f
date-d last-day +%y-%m-%d
date-d yesterday +%y-%m-%d
date-d next-day +%y-%m-%d date-d Tomorro
W +%y-%m-%d
date-d ' 2 days ago ' +%y-%m-%d
date-d ' 2 weeks ago ' +%y-%m-%d
date-d ' 2 months ago ' +%y-%m-%d
date-d ' 2 years ago ' +%y-%m-%d
date-d ' 2 days ' +%y-%m-%d
date-d ' 2 weeks ' +%y-%m-%d
date-d ' 2 months ' +%y-%m-%d
date-d ' 2 years ' +%y-%m-%d date-d last-month +%y-%m-%d date-d next-month +%y-%m-%d
Date -D next-year +%y-%m-%d
date +%y-%m-%d-%h-%m
date +%y-%-m-%d-%-h-%-m
Date commands and system time settings for Linux
The Linux clock is divided into system clocks (systems Clock) and hardware (real time Clock, short RTC) clocks. The system clock is the clock in the current Linux kernel, and the hardware clock is the battery-powered clock on the motherboard, which can be set in the BIOS. When Linux is started, the hardware clock will read the system clock settings, and the system clock will be independent of the hardware operation.
All the commands (including functions) in Linux are set by the system clock. In Linux, the commands for clock viewing and setting are mainly date, Hwclock.
1. Date
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: minutes (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: Seconds (00-60)
%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 (JAN-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: Weeks of the Year (00-53) (with Sunday as the first day of the week)
%w: Day of the Week (0-6)
%w: The first few weeks of the year (00-53) (with Monday as the day 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, and 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 '
Note: When you do not want to appear 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: Modifying 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
At the same time modify the date time, note to add double quotes, date and time between a space, enter:
#date-S "2007-08-03 14:15:00"
2. View hardware Time
# Hwclock
Set Hardware time
# hwclock-set-date= "07/07/06 10:19" (Month/day/year: minutes: SEC)
3, hardware time and system time synchronization
According to the previous version, reboot the system, hardware time will read the system time, to achieve synchronization, but do not reboot, the need to use the Hwclock command to achieve synchronization.
The hardware clock synchronizes with the system clock:
# Hwclock--hctosys (HC represents hardware time, SYS represents system time)
system clock and Hardware clock synchronization: (Let system time sync to hardware clock)
# HWCLOCK–SYSTOHC
This article comes from "learning, feeling, experience" blog