Perl and the shell get the code _perl of Yesterday, tomorrow, or more days before the date

Source: Internet
Author: User
Tags current time time zones date two weeks ago

First, how does Perl get

Copy Code code as follows:

#!/usr/bin/perl-w
Use POSIX QW (strftime);
My $day = strftime ("%y%m%d", LocalTime (time-24*3600)); #获取昨天的日期

Second, in Linux on the man date-d parameters of the analogy of general, the following example further explained:

# D,--date=string display time described by STRING, not ' now '
[Root@gman root]# date-d next-day +%y%m%d #明天日期
20091024
[Root@gman root]# date-d last-day +%y%m%d #昨天日期
20091022
[Root@gman root]# date-d yesterday +%y%m%d #昨天日期
20091022
[Root@gman root]# date-d tomorrow +%y%m%d # tomorrow date
20091024
[Root@gman root]# date-d last-month +%y%m #上个月日期
200909
[Root@gman root]# date-d next-month +%y%m #下个月日期
200911
[Root@gman root]# date-d next-year +%y #明年日期
2010
date=$ (Date +%y%m%d-d ' 2 days ago ') #获得2天前的日期

20111022

date=$ (Date +%y%m%d-d ' 2 day ') #获得2天后的日期

20111026

Nominal: Date

Use of authority: for the benefit of the user
Measures taken: date [u] [D datestr] [-S datestr] [--UTC] [--universal] [--DATE=DATESTR] [--SET=DATESTR] [--help] [--version] [+f ORMAT] [MMDDHHMM[[CC]YY][.SS]]
Explanation: Date can be used to reveal or set the system of dates and time, in the disclosure, the user can set to reveal the style, style set to a plus after a number of symbols, the list of available symbols are as follows:
In terms of effort:
%: Printed out
%%n: Next line
%t: Jump Lattice
%H: Hours (00..23)
%I: Hours (01..12)
%k: Hours (0..23)
%l: Hours (1..12)
%m: Min (00..59)
%p: Revealing local AM or PM
%r: Direct revelation Time (12 hours system, style is HH:MM:SS [ap]m)
%s: Number of seconds from January 1, 1970 00:00:00 UTC to date%s: sec (00..61)
%T: Direct revelation Time (24-hour system)
%x: Equivalent to%h:%m:%s
%Z: Revealing time zones
Date aspect:
%a: Sunday, Sun. Sat)
%A: Monday (Sunday. Saturday)
%b: Month. DEC)
%B: Month (January. December)
%c: Direct revelation of date and time
%d: Day (01..31)
%d: Direct revelation date (MM/DD/YY)
%h: With%b
%j: The first day of the Year (001..366)
%m: Month (01..12)
%u: The week of the Year (00..53) (with Sunday as the first day of the week)
%w: The first day of the Week (0..6)
%w: The first few weeks of the year (00..53) (in Monday case for day one of the week)
%x: Direct revelation Date (MM/DD/YY)
%y: Last two digits of the year (00.99)
%Y: Full year (0000..9999)
If you do not start with a plus sign, it means setting the time, and the time style is MMDDHHMM[[CC]YY][.SS],
Where MM is the month,
DD is the day,
HH for the Hour,
MM for minutes,
CC is the first two digits of the year,
YY is the two digits after the year,
SS is second number
The meter:
-D Datestr: Revealing the time set in DATESTR (not system time)
--help: Revealing Help messages
-S DATESTR: Set the system time to the time set in the DATESTR
-U: Revealing the current Greenwich time
--version: Revealing the version number
Example:
Revealing time after hop, and then revealing the date: dated +%t%n%d
Revealing months and days: Date +%b%d
Revelation Date and setting time (12:34:56): Date--date 12:34:56
Set the system current time (12:34:56): Date--s 12:34:56
Beware: When you are not eager to reveal meaningless 0 o'clock (say 1999/03/07), you can insert symbols in the symbol, for example, the date +%-h:%-m:%-s will remove the meaningless 0 from the minute, as if the original 08:09:04 would become 8:9:4. In addition, only those who get permission (say root) can set system time. When you changed the system time as root, please remember to clock-w the system to the CMOS, so the system will continue to hold the latest accurate value the next reboot.
NTP time synchronization
The NTP service is installed by default on the Linux system, and the NTP synchronization is manually held as follows
Ntpdate ntp1.nl.net
Of course, you can also specify a different NTP server
-------------------------------------------------------------------
Stretching function
The date tool can end up working more than just printing out the current system date. You can use it to get the number of weeks that a given date is, and to get a relative date relative to the current date. Asking how many days a day is a week
Another extension of GNU's call to date is the-D option, which is extremely useful when you don't have a calendar table on your desk (UNIX users don't need a calendar table). With this powerful option, you can quickly find out what a particular date is, by passing the supply of parameters that enclose the date as quotation marks:
$ date-d "Nov 22"
Wed Nov 00:00:00 EST 2006
$
In this example, you can see that the November 22 of this year is Thursday three.
So, assuming that a major meeting is held on November 22, you will be able to instantly hear that day is Wednesday, and that day you'll be at the office of the resident.
Get relative date
The D option can also tell you what day it is, relative to the current date, from a number of days or weeks from now onwards, possibly past (past). Passing this relative offset in quotation marks, as a parameter to the-D option, can end this task.
For example, you must inquire about the date two weeks thereafter. In case you are at the Shell reminder, you can get the answer quickly:
$ Date-d ' 2 weeks '
There are other important measures to take advantage of this call. Using the Next/last call, you will be able to obtain the day of the week following:
$ Date-d ' next Monday ' (date of next Monday)
$ date-d next-day +%y%m%d (tomorrow's date) may be: date-d tomorrow +%y%m%d
$ date-d last-day +%y%m%d (yesterday's date) may: Date-d Yesterday +%y%m%d
$ date-d last-month +%y%m (last month was a few months)
$ date-d next-month +%y%m (next month is a few months)
Using the ago call, you can get past dates:
$ Date-d ' day ago ' (30 days before date)
You can take advantage of negative numbers to get the opposite date:
$ Date-d ' Dec 14-2 weeks ' (relative: Dec 14 date two weeks ago)
$ Date-d ' -100 days ' (100 Day Past date)
$ Date-d ' (50 days after 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.

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.