Linux Date Command Detailed

Source: Internet
Author: User
Tags locale month name rfc set time

Date: The command to display the time

Common Command Parameters

Usage: date [options] ...  [+ format] or: Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]] Displays the current time in the given format, or sets the system date.          -D,--date= string displays the time described by the specified string, instead of the current time-F,--file= date file is similar to--date, read-in time from a date file by line-R,--reference= file Displays the last modified time of file specified file-r,--rfc-2822 output date and time in RFC 2822 format for example: August 7, 2006, Monday 12                                : 34:56-0600--rfc-3339=timespec outputs the date and time in RFC 3339 format.                                timespec= ' Date ', ' seconds ', or ' ns ' represents the display precision of the date and time. The date and time unit is separated by a single space: 2006-08-07 12:34:56-06:00-s,--set= string sets the specified string to separate the time-u,-- UTC,--universal output or set Coordinated Universal Time--HELP Display this help information and exit--version display version information and exit given format control output,   The sequence of explanations is as follows: percent of a literal%a the current locale's abbreviated weekday name (for example: Day, for Sunday)%a the full name of the current locale (e.g. Sunday)%b the month name of the current locale (ex: one, for January)  %B the full month name of the current locale (for example: January) The date and time of the current locale of%c (e.g. Thursday, March 3, 2005 23:05:25)%c  A century; For example, a%Y, typically omitting the last two digits of the current year (for example:)%d date by month (ex: £ º)%d Date by month, equal to%m/%d/%y%e date by month, add a space equal to%_d%F full date format, equivalent to the last two bits of the%y-%m-%d%g ISO-8601 format year (see%G)%g ISO-8601 format year    (see%V), generally only used in conjunction with%V%h equals%b%h hours (00-23)%I Hours (00-12)%j years (001-366)%k (0-23)%l (1-12)%m month (01-12)%m (00-59)%n newline%n nanoseconds (000000 000-999999999)%p "Morning" or "afternoon" under the current locale, the output is empty when unknown%p is similar to%p, but the output lowercase letter%r The 12-hour clock time under the current locale (e.g. 11:11:04 pm)% R 24 hours time and minutes, equivalent to%h:%m%s since UTC time 1970-01-01 00:00:00 the number of seconds after%s seconds (00-60)%t Output tab tab%t time, equals%h:%m: %s%u week, 1 represents the week of the year of Monday%u, with Sunday being the first day of the Week (00-53)%V ISO-8601 format Specification for the week ordinal of the year, with Monday being the first day of the Week (01-53)%w the day of the Week (0-6), 0 represents the week of the Monday%W year, in Monday, the date description under the current locale of the first day of the Week (00-53)%x (for example: 12/31/99)%x time description under current locale (e.g. 23:13:48)%y year        Post two-digit (00-99)%Y year%z +HHMM digital time zone (for example, -0400)%:z +hh:mm Digital time zone (for example, -04:00)%::z +hh:mm:ss Digital time zone (for example, -04:00:00)%:::Z-numeric time zone with the necessary precision (for example, -04,+05:30)%Z alphabetical sort of time zone abbreviation (for example, EDT) by default, the numeric area of the date is populated with 0. The following optional tag can be followed by "%" after:-(hyphen) does not populate the field _ (underscore) with a space padding 0 (number 0) with 0 padding ^ If possible, use uppercase letters # If possible, use the opposite case after any tag also allows an optional field width specified, which is a decimal number. As an optional cosmetic declaration, it can be E, use the Local Environment association representation if possible, or O, where possible, use the number symbol associated with the local environment.

Common Command Display

Commonly used symbols

-F Output Long format character Month Day
Date +%f-2017-08-02


-y output Short format characters
Date +%y-%m-%d-->17-08-02


-h-m-s: Output hours and seconds
Date +%y-%m-%d\%h-%m-%s-->17-08-02 21-16-14
Date +%y-%m-%d\%h:%m:%s-->17-08-02 21:16:14


-H Output Month

-T: direct hours and seconds
Date +%f\%T-2017-08-02 21:18:14


-W: Shows the day of the week
Date +%w Wednesday


-D: Show days in advance/postpone
Date +%f-d " -1day" 2017-08-01
Date +%f 2017-08-02
Date +%f-d "+1day" 2017-08-03

Date +%f\%h:%m:%s-d "+2hour 2min 2sec" 2017-08-02 23:40:49-2 hours in advance 2 minutes 2 seconds
Date +%f\%h:%m:%s 2017-08-02 21:38:47
Date +%f\%h:%m:%s-d " -2hour-2min-2sec" 2017-08-02 19:36:45-Delayed 2 hours, 2 minutes, 2 seconds

Displays the current month day time

Date + (%F%T) Date +%f\%T   # Effect ditto

In terms of setting the time:

Date–s 01:01:01//Set time, no changes made to date

Date-s ' 2018-07-07 10:50 '//This will set all the time

Time plus minus:

Date +%y%m%d\%t-d "1hour"//This can be set for a time delay of one hours, provided that the display has an hour

Date +%y%m%d-d "1day"//This can set the time to postpone the day

Date +%y%m%d--date= "+1 days"//Display the day before

Date +%y%m%d--date= "-1 days"//day after display

Common time synchronization
1. Locally modified   date-s "2017/07/30 18:39"   hwclock            #同步时间到shell2. Synchronize Internet time ntpdate time.windows.com   ( Ntpdate is a code for internal synchronization time)

Linux Date Command Detailed

Related Article

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.