AIX systems can use the time zone change method to get the date of N days before and after

Source: Internet
Author: User

The date command does not have the-D option in the AIX system and does not receive the entered value.
In an AIX system, if you want to get a few days or days after the current time, you can use the method that changes the current timezone.
Export Tz=beist-8 is the system current time.
Adjusting the time zone can change times.
For example: Get the time of next week export tz=beist-176, 176 is obtained by (24*7+8)
Gets the time of the previous week export tz=beist+160, 160 is obtained by (24*7-8)
Adjusting the time zone only changes the current window, but it has no effect on the server, but it is recommended that the time zone be adjusted back (export tz=beist-8) with no effect on the system.

The functions are as follows:

Daysafter ()
{
# $1:the number of days before or after today
# $2:the Format of date
Currenttz= ' echo $TZ '
if (($ > 0))
Then
Timezonediff= ' echo 24*$1+8 | BC '
Export tz=beist-$TimeZoneDiff
Elif (($ = 0)); then
:
Else
timezonediff= ' Echo-24*$1-8 | BC '
Export tz=beist+ $TimeZoneDiff
Fi

Date + "$"
Export tz= $CurrentTZ
}

Test:

$ daysafter 0 "%y-%m-%d%T"
2011-06-02 10:37:11
$ daysafter 7 "%y-%m-%d%T"
2011-06-09 10:37:29
$ daysa Fter-7 "%y-%m-%d%T"
2011-05-26 10:37:40

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.