Linux date format output time and date

Source: Internet
Author: User
Tags current time iso 8601 iso 8601 format linux date format rfc set time time and date

Date command Arguments

-d,–date=string Displays the time specified by STRING
-f,–file=datefile A similar –date parameter to display the time per line in a Datefile file
-itimespec,–iso-8601[=timespec] Displays the date/time in ISO 8601 format. Timespec is "date" (Show only date), "hours

"," Minutes "," Senconds "(Display time precision), default to" date ".
-r,–reference=file Displays 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


Example.

[Root@108test ~]# date-d today + "%y-%m-%d"
2008-05-07
[Root@108test ~]# date-d today + "%y_%-m_%-d"
2008_5_7
[Root@108test ~]# date-d today + "%y-%m-%d%T"
2008-05-07 14:55:19
[Root@108test ~]# date-d today + "%y-%m-%d%h:%m"
2008-05-07 14:55
[Root@108test ~]# date-d today + "%y-%m-%d%h:%m:%s"
2008-05-07 14:55:57

The real date command itself provides a date addition and subtraction operation

Very convenient. For example: Get yesterday's time
Date +%y%m%d--date= "-1 day"

Date usage: date [OPTION] ... [+format]
Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]]
Date can be used to display or set the system's dates and times.
1. 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 is as follows:%: Hit

Print%
%n: Next line
%t: Jump
%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, format hh:mm:ss [ap]m)
%s: Seconds from January 1, 1970 00:00:00 UTC
%s : Seconds (00..61)
%T: Direct display time (24-hour)
%x: equivalent to%h:%m:%s
%Z: Show time zone%a: Day of the Week (Sun. Sat)
%A: Day of the Week (Sunday. Saturday)
%b: Month. DEC)
%B: Month (January. December)
%c: Show date and time directly
%d: Day (01..31)
%d: Direct display date (MM/DD/YY)
%h: Same%b
%j: Day of the Year (001..366)
%m: Month (01..12)
%u: The Week of the Year (00..53) (in Sunday case of the first day of the week)
%w: Day of the Week (0..6)
%w: Weeks of the Year (00..53) (to Mond Ay as the first day of the week)
%x: Direct display date (MM/DD/YY)
%y: Last two digits of year (00.99)
%y: Full year (0000..9999)

2. In the set time aspect
Date-s//Set the current time, only root permission can be set, others can only view.
Date-s 20080523//set to 20080523, which will set the time to empty 00:00:00
Date-s 01:01:01//Set specific time, will not make changes to the date
Date-s "01:01:01 2008 -05-23″//This allows you to set the full time
Date-s "01:01:01 20080523″//so you can set all the time
Date-s" 2008-05-23 01:01:01″//so you can set all the time
Date -S "20080523 01:01:01″//This allows you to set the full time
3. Add minus
Date +%y%m%d        // Show the day before yesterday date
Date +%y%m%d--date= "+1 Day"  //show date of day before
date +%y%m%d--date= "-1 days"  //Display the date after the
date +%y%m %d--date= "-1 month"  //display on January date
Date +%y%m%d--date= "+1 Month"  //Show next January date
Date +%y%m%d--date= "-1 year " //Display previous year's date
Date +%y%m%d--date=" +1 Year " //Display the date of the following years

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.