Linux system time

1、date Commands are used to view and modify Linux Time of the system , About date The detailed help document for the command is as follows

[[email protected] ~]# date --help

Usage: date [OPTION]... [+FORMAT]

 or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

Display the current time in the given FORMAT, or set the system date.

 

 -d, --date=STRING         display time described by STRING, not `now'

 -f, --file=DATEFILE       like --date once for each line of DATEFILE

 -r, --reference=FILE      display the last modification time of FILE

 -R, --rfc-2822            output date and time in RFC 2822 format.

                           Example: Mon, 07 Aug 2006 12:34:56 -0600

     --rfc-3339=TIMESPEC   output date and time in RFC 3339 format.

                           TIMESPEC=`date', `seconds', or `ns' for

                           date and time to the indicated precision.

                           Date and time components are separated by

                           a single space: 2006-08-07 12:34:56-06:00

 -s, --set=STRING          set time described by STRING

 -u, --utc, --universal    print or set Coordinated Universal Time

     --help     display this help and exit

     --version  output version information and exit

 

FORMAT controls the output.  Interpreted sequences are:

 

 %%   a literal %

 %a   locale's abbreviated weekday name (e.g., Sun)

 %A   locale's full weekday name (e.g., Sunday)

 %b   locale's abbreviated month name (e.g., Jan)

 %B   locale's full month name (e.g., January)

 %c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)

 %C   century; like %Y, except omit last two digits (e.g., 20)

 %d   day of month (e.g, 01)

 %D   date; same as %m/%d/%y

 %e   day of month, space padded; same as %_d

 %F   full date; same as %Y-%m-%d

 %g   last two digits of year of ISO week number (see %G)

 %G   year of ISO week number (see %V); normally useful only with %V

 %h   same as %b

 %H   hour (00..23)

 %I   hour (01..12)

 %j   day of year (001..366)

 %k   hour ( 0..23)

 %l   hour ( 1..12)

 %m   month (01..12)

 %M   minute (00..59)

 %n   a newline

 %N   nanoseconds (000000000..999999999)

 %p   locale's equivalent of either AM or PM; blank if not known

 %P   like %p, but lower case

 %r   locale's 12-hour clock time (e.g., 11:11:04 PM)

 %R   24-hour hour and minute; same as %H:%M

 %s   seconds since 1970-01-01 00:00:00 UTC

 %S   second (00..60)

 %t   a tab

 %T   time; same as %H:%M:%S

 %u   day of week (1..7); 1 is Monday

 %U   week number of year, with Sunday as first day of week (00..53)

 %V   ISO week number, with Monday as first day of week (01..53)

 %w   day of week (0..6); 0 is Sunday

 %W   week number of year, with Monday as first day of week (00..53)

 %x   locale's date representation (e.g., 12/31/99)

 %X   locale's time representation (e.g., 23:13:48)

 %y   last two digits of year (00..99)

 %Y   year

 %z   +hhmm numeric timezone (e.g., -0400)

 %:z  +hh:mm numeric timezone (e.g., -04:00)

 %::z  +hh:mm:ss numeric time zone (e.g., -04:00:00)

 %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)

 %Z   alphabetic time zone abbreviation (e.g., EDT)

 

By default, date pads numeric fields with zeroes.

The following optional flags may follow `%':

 

 -  (hyphen) do not pad the field

 _  (underscore) pad with spaces

 0  (zero) pad with zeros

 ^  use upper case if possible

 #  use opposite case if possible

 

After any flags comes an optional field width, as a decimal number;

then an optional modifier, which is either

E to use the locale's alternate representations if available, or

O to use the locale's alternate numeric symbols if available.

 

Report date bugs to [email protected]

GNU coreutils home page: <http://www.gnu.org/software/coreutils/>

General help using GNU software: <http://www.gnu.org/gethelp/>

For complete documentation, run: info coreutils 'date invocation'

date Common format and parameter description

date +%F === date +%Y-%m-%d     Show the year, month and day

[[email protected] ~]# date +%F

2018-04-13

[[email protected] ~]# date +%Y-%m-%d

2018-04-13

date +%T === date +%H-%M-%S     Display minutes and seconds

[[email protected] ~]# date +%T

21:39:42

[[email protected] ~]# date +%H-%M-%S

21-39-49

date +%F\ %T     Display year, month, day, hour, minute and second

[[email protected] ~]# date +%F\ %T

2018-04-13 21:41:23

date +%y     Show two digit year

[[email protected] ~]# date +%y

18

date +%Y     Show four digit year

[[email protected] ~]# date +%Y

2018

date +%m      Show month

[[email protected] ~]# date +%m

04

date+%M      Show minutes

[[email protected] ~]# date +%M

42

date +%d      Display day

[[email protected] ~]# date +%d

13

date+%p or %P      It shows that AM(am) or PM(pm)

[[email protected] ~]# date +%P

pm

[[email protected] ~]# date +%p

PM

date +%u      Show the day of the week

[[email protected] ~]# date +%u

5

date +%H      Hours 24 hourly (00~23)

[[email protected] ~]# date +%H

21

date +%I      Hours 12 hourly (01~12)

[[email protected] ~]# date +%l

9

date+ %j      Shows the day of the year

[[email protected] ~]# date +%j

103

date+%W     Shows the week of the year

[[email protected] ~]# date +%W

15

date -d '-3day'     Show the date of the first three days

[[email protected] ~]# date -d '-3day'

Tue Apr 10 21:45:46 CST 2018

date -s '20180401 08:20:00'     Setup time

[[email protected] ~]# date -s '20180401 08:20:00'

Sun Apr  1 08:20:00 CST 2018

 

2、 Synchronous time command ntpdate

ntp === network  time protocol Network time protocol

Using time servers ( Alicloud, etc ), You can also add this command to a scheduled task , Give Way Linux System timing synchronization time

ntpdate ntp1.aliyun.com

ntpdate ntp2.aliyun.com

ntpdate ntp3.aliyun.com

ntpdate ntp4.aliyun.com

ntpdate ntp5.aliyun.com

ntpdate ntp6.aliyun.com

 

3、cal Show calendar

-1 Show a month's calendar

-3 One month before the display system , The current month , Next month's calendar

-s   Show Sunday as the first day of the week , Default format

-m Show Monday as the first day of the week

-j   On the day of the year ( The date of the year is calculated by day , from 1 month 1 Starting from the number , By default, the number of days of the current month in a year is displayed )

-y   Displays all the months of the calendar for the current year

[[email protected] ~]# cal -y

                              2018                              

 

      January               February                 March      

Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa

   1  2  3  4  5  6                1  2  3                1  2  3

7  8  9 10 11 12 13    4  5  6  7  8  9 10    4  5  6  7  8  9 10

14 15 16 17 18 19 20   11 12 13 14 15 16 17   11 12 13 14 15 16 17

21 22 23 24 25 26 27   18 19 20 21 22 23 24   18 19 20 21 22 23 24

28 29 30 31            25 26 27 28            25 26 27 28 29 30 31

 

       April                   May                   June        

Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa

1  2  3  4  5  6  7          1  2  3  4  5                   1  2

8  9 10 11 12 13 14    6  7  8  9 10 11 12    3  4  5  6  7  8  9

15 16 17 18 19 20 21   13 14 15 16 17 18 19   10 11 12 13 14 15 16

22 23 24 25 26 27 28   20 21 22 23 24 25 26   17 18 19 20 21 22 23

29 30                  27 28 29 30 31         24 25 26 27 28 29 30

 

       July                  August                September    

Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa

1  2  3  4  5  6  7             1  2  3  4                      1

8  9 10 11 12 13 14    5  6  7  8  9 10 11    2  3  4  5  6  7  8

15 16 17 18 19 20 21   12 13 14 15 16 17 18    9 10 11 12 13 14 15

22 23 24 25 26 27 28   19 20 21 22 23 24 25   16 17 18 19 20 21 22

29 30 31               26 27 28 29 30 31      23 24 25 26 27 28 29

                                             30

      October               November               December      

Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa

   1  2  3  4  5  6                1  2  3                      1

7  8  9 10 11 12 13    4  5  6  7  8  9 10    2  3  4  5  6  7  8

14 15 16 17 18 19 20   11 12 13 14 15 16 17    9 10 11 12 13 14 15

21 22 23 24 25 26 27   18 19 20 21 22 23 24   16 17 18 19 20 21 22

28 29 30 31            25 26 27 28 29 30      23 24 25 26 27 28 29

                                             30 31

 

4、hwclock Command is a hardware clock access tool , It shows the current time 、 Setting hardware clock time and setting hardware clock to system time , You can also set the system time to the time of the hardware clock .

stay Linux There are two kinds of clocks, hardware clock and system clock .

Hardware clock refers to the clock device on the motherboard , That is, it is usually available in BIOS The clock set by the screen .

The system clock ( Software clock ) Means kernel The clock in . When Linux Startup time , The system clock will read the setting of the hardware clock , Then the system clock operates independently . all Linux Related instructions and functions are to read the system clock settings .

Parameter description :

--adjust:hwclock Every time you change the hardware clock , It will be recorded in /etc/adjtime In file . Use --adjust Parameters , Can make hwclock Estimate the hardware clock offset from previous records , And used to correct the current hardware clock ;

--debug: Show hwclock Execution time details

--directisa:hwclock Presupposition from /dev/rtc Device to access the hardware clock . If it cannot be accessed , You can use this parameter directly to I/O Instructions to access the hardware clock

--hctosys: Adjust the system clock to match the current hardware clock

--systohc: Adjust the hardware clock to match the current system clock

--set --date=< Date and time >: Set the hardware clock

--show: Displays the time and date of the hardware clock

--test: Just test the program , Instead of actually changing the hardware clock

--utc: To use Greenwich mean time , Please add this parameter ,hwclock Will perform the conversion work

--version: Display version information