Use the shell in Linux to get yesterday, tomorrow, or more days before the date

Source: Internet
Author: User

Tags: scribe file in TP server Greenwich SPAN last for hint name

use the shell in Linux to get yesterday, tomorrow or many days before the date time -- A- ,  the: -:xxblogjava-Expert Area Original http://www.blogjava.net/xzclog/archive/2015/12/08/428555.htmlTheme Shell Original address: http://www.itwis.com/html/os/linux/20100202/7360.htmlLinux uses the shell to get yesterday, tomorrow or many days ago: on the man date in Linux-the D parameter is more ambiguous, the following examples further illustrate: #-D,--date=string display time described by STRING, not ' now ' [[email protected] root]# date-D next-day +%y%m%D #明天日期20091024[[email protected] root]# date-D last-day +%y%m%D #昨天日期20091022[[email protected] root]# date-D Yesterday +%y%m%D #昨天日期20091022[[email protected] root]# date-D Tomorrow +%y%m%D # tomorrow's date20091024[[email protected] root]# date-D last-month +%y%m #上个月日期200909[[email protected] root]# date-D next-month +%y%m #下个月日期200911[[email protected] root]# date-D next-year +%Y #明年日期 .DATE=$ (Date +%y%m%d--date'2 days ago') #获取昨天或多天前的日期名称: Date usage rights: All user usage: date [-U] [-D DATESTR] [-S datestr] [--UTC] [--universal] [--DATE=DATESTR] [--Set=DATESTR] [--help] [--version] [+FORMAT] [MMDDHHMM[[CC]YY][.SS]] Description: Date can be used to display or set the system's Day and time, in terms of display, the user can set the format to be displayed, the format is set to a plus followed by a number of tags, where the list of available tags is as follows: Time:%: Print out% %N: Next line%t: Jump Grid%H: Hours (xx.. at)  %I: Hours ( on.. A)  %k: Hours (0.. at)  %l: Hours (1.. A)  %M: Minutes (xx.. -)  %P: Show local AM or PM%r: Show Time directly ( Ahours, formatted as HH:MM:SS [Ap]m]%s: From1970Years1Month1Dayxx:xx:xxNumber of seconds in UTC so far%s: seconds (xx.. A)  %T: Show Time directly ( -hour system)%x: Equivalent to%h:%m:%S%Z: Displays the 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: Display the date and time directly%d: Day ( on.. to)  %d: Display date directly (mm/dd/yy)%h: Same%b%j: The day ordinal of a year (001..366)  %m: Month ( on.. A)  %u: The week ordinal of the year (xx.. -) (in the case of Sunday as the first day of the week)%w: The day of the Week (0..6)  %W: The first week of the year (xx.. -) (in the case of Monday as the first day of the week)%x: Show date directly (mm/dd/yy)%y: The last two digits of the year (00.99)  %Y: Full Year (0000..9999If you do not start with a plus, it means to set the time, and the time format is MMDDHHMM[[CC]YY][.SS], where mm is the month, DD for the day, HH for the hour, MM for minutes, CC for the first two digits of the year, YY for the year after the two digits, SS is the number of seconds: /c5>-D datestr: Displays the time set in the DATESTR (non-system time)--Help: Display auxiliary messages-s DATESTR: Set the system time to the time set in Datestr-u: Show the current GMT--Version: Displays the revision number example: Skip after the time, and then displays the current date as: date+%t%n%d Display month and day: Date+%b%d Display date and set time ( A: the: About): Date--date A: the: Aboutset the current time of the system ( A: the: About): Date--s A: the: AboutNote: When you don't want to appear meaningless0When (for example,1999/Geneva/ -), you can insert-a symbol in the tag, for example, date +%-h:%-m:%-s will not make sense in seconds0To be removed, like the original. ,: the:Genevawill become8:9:4。 In addition, the system time can be set only if the authority (for example, Root) is acquired. When you change the system time as root, remember to use the clock-W to write the system time to the CMOS so that the system time will continue to hold the latest correct value the next time the power is rebooted. NTP time synchronization Linux system installed by default NTP service, manual NTP synchronization as follows Ntpdate Ntp1.nl.net of course, can also specify other NTP server-------------------------------------------------------------------Extended functionality The Date tool can do more work than just print out the current system date. You can use it to get a given date exactly what the day of the week is, and get a relative date compared to the current date. Know the day of the week another extension of the GNU to date command is-d option is useful when there is no Calendar table on your table (UNIX users do not need a calendar table). With this powerful option, you can quickly find out exactly what day of the week a particular date is, by providing a date as an argument in quotation marks: $ date-D"Nov"Wed Nov A xx:xx:xxEst2006$ In this example, you can see that this year's OneMonth Athe day is Wednesday. So, suppose that in OneMonth AA major meeting of the day, you can immediately learn that the day is Wednesday, and this day you will be rushed to the resident office. The Get relative Date D option can also tell you what day it is, relative to the current date, several days or weeks from now, or before (past). By enclosing this relative offset in quotation marks, as-parameter of the D option, you can complete this task. For example, you need to know the date after two weeks. If you are at the Shell prompt, you can get the answer quickly: $ date-d '2weeks ' There are some other important ways to use this command. Use next/last instruction, you can get what day of the week after: $ date-D'next Monday'(date of next Monday) $ date-D Next-day +%y%m%d (tomorrow's date) or: Date-d tomorrow +%y%m%D $ date-D Last-day +%y%m%d (yesterday's date) or: date-d yesterday +%y%m%D $ date-D last-month +%y%m (last month is a few months) $ date-D next-month +%y%m (next month is months) using the AGO directive, you can get past the date: $ date-D'Days ago'(date 30 days ago) You can use negative numbers to get the opposite date: $ Date-D'Dec 14-2 weeks'(relative: Dec 14 date two weeks before date) $ date-D'-100 Days'(date 100 days ago) $ date-D' Days'(date after 50 days) This technique is very useful, it can set a reminder for itself based on a future date, possibly in a script or Shell startup file, as follows: Day= ' date-d'2 weeks'+"%b%d"`ifTest"' echo $DAY '"=" About"; Then Echo'Product Launch is now weeks away!'; Fi

Use the shell in Linux to get yesterday, tomorrow, or more days before the date

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.

Tags Index: