Date usage of Linux

Source: Internet
Author: User
Tags iso 8601 iso 8601 format rfc set time

Display time is a common command, and it is often used in writing shell scripts to display date-related file names or times. The date command is both Linux and Windows.

The use of the date command under Linux

    • Date [OPTION] ... [+format]
    • Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]]

Date command Arguments

    • -d,–date=string displays the time specified by the STRING
    • -f,–file=datefile similar –date parameter displays the time of each line in the Datefile file
    • -ITIMESPEC,–ISO-8601[=TIMESPEC] Displays the date/time in ISO 8601 format. Timespec is one of "date" (dates only), "hours", "Minutes", "Senconds" (Display time precision), and defaults to "date".
    • -r,–reference=file display the last modified time of the file
    • -r,–rfc-2822 display time in RFC-2822 compatible date format
    • -s,–set=string set Time to STRING
    • -u,–utc,–universal display or set to Coordinated Universal Time format

Date command output display format

  • Percent character%
  • %a week abbreviation (Sun. Sat)
  • %A full name of the week (Sunday). Saturday)
  • %b abbreviation for month (Jan: DEC)
  • Full name of the%B month (January). December)
  • %c Date Time (Sat 12:02:33 EST 1989)
  • %c century (year except 100 after finishing) [00-99]
  • %d the day of the one month (01..31)
  • %d Date (MM/DD/YY)
  • %e Day of one months (1..31)
  • %F date, same as%y-%m-%d
  • %g year (YY)
  • %G year (yyyy)
  • %h with%b
  • %H hours (00..23)
  • %I Hours (01..12)
  • %j the first day of the Year (001..366)
  • %k hours (0..23)
  • %l hours (1..12)
  • %m Month (01..12)
  • %M min (00..59)
  • %n line break
  • %N nanosecond (000000000..999999999)
  • %p AM or PM
  • %P am or PM
  • %r 12-hour time (Hh:mm:ss [ap]m)
  • %R 24-hour time (hh:mm)
  • %s number of seconds starting from 00:00:00 1970-01-01 UTC
  • %s seconds (00..60)
  • %t tab
  • %T 24-hour time (HH:MM:SS)
  • The day of the week of%u (1..7); 1 = Monday
  • %u week of the year, Sunday for the first day of the Week (00..53)
  • %V Week of the year, Monday is the first day of the Week (01..53)
  • %w Day of the Week (0..6); 0 on behalf of Sunday
  • %W Week of the year, Monday is the first day of the Week (00..53)
  • %x Date (MM/DD/YY)
  • %x Time (%h:%m:%s)
  • %y Year (00..99)
  • %Y year (1970 ...)
  • %Z RFC-2822 Style digital format time zone (-0500)
  • %Z time zone (e.g., EDT), the time zone is not determined to be empty

A custom time example illustrates:

[Email protected] test]#DateThursday, October 12, 2017Geneva: +: ACst[[email protected] test]#Date-I .-Ten- A[email protected] test]#Date-ihours .-Ten-12t03+0800[email protected] test]#Date-iminutes .-Ten-12t03: A+0800[email protected] test]#Date-Iseconds .-Ten-12t03: A: A+0800[email protected] test]#Date-Rthu, AOct . Geneva: the: A+0800[email protected] test]#Date-u2017 Wednesday, October 11 +: the: +Utc[[email protected] test]#Date+"Today is%A."Today is Thursday. [Email protected] test]#Date+"date:%b.%e,%G"date:10 month. A, .[email protected] test]#Date+"Date:%b.%e,%G"date:10 month. A, .[email protected] test]#Date+"%x%x"October 12, 2017 03:42 56 seconds [[email protected] test]#Date+"%y-%m-%d%h:%m:%s" .-Ten- A Geneva: +: -[email protected] test]#Date+"%y-%m-%d%i:%m:%s%p" .-Ten- A Geneva: +: -morning [[email protected] test]#

Common time Formats:

Date " +%y-%m-%d%h:%m:%s " $-ten:$-date"  +%y-%m-%d " [email protected] test]# 

Linux date Plus and minus operations

[Email protected] test]#Date#正常时间2017年 Thursday, October 12Geneva: the: theCst[[email protected] test]#Date+"%b%e,%G"#自定义时间格式10月 A, .[email protected] test]#Date+"%b%e,%G"-D'-1 Day'#时间减1天, plus 1 days like October One, .[email protected] test]#Date+"%b%e,%G"-D'+1 Month'#时间加一个月, minus one months like November A, .[email protected] test]#Date+"%y year%m month%d day"#自定义时间格式, Date October 12, 2017 [email protected] test]#Date+"%y year%m month%d day"-D'-1 Day'#同上面加减1天 (or plus minus January) October 11, 2017 [[email protected] test]#Date+"%y year%-m month%d day"#去除月份前的0, for example ' August 12, 2017 ' displayed as ' August 12, 2017 ' October 12, 2017 [[email protected] test]#Date-D'-1 Day'+"%b%e,%G"#时间减1天, plus 1 days like October One, .[email protected] test]#Date-D'+1 Month'+"%b%e,%G"#时间加一个月, minus one months like November A, .[email protected] test]#

Date usage of Linux

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.