Date calculation usage in different Unix environments

Source: Internet
Author: User

From: http://blog.rootshell.be/2006/05/04/solaris-yesterday-date/

Solaris & yesterday date?

The GNU version of date (1) has a nice flag-Date. It's very easy to format dates in the past or future:

$ Date + % d-% m-% Y04-05-2006 $ date -- date yesterday + % d-% m-% Y03-05-2006 $ date -- date "-6 months" + % d-% m -% Y04-11-2005

The Solaris version of date (1) has no such nice flags. So, how to print another date?

Direct in a shell:

$ YESTERDAY = 'tz = GMT + 24 date + % d-% m-% y '; echo $ YESTERDAY03-05-2006 $ YESTERDAY = 'tz = GMT-48 date + % d-% m-% y'; echo $ YESTERDAY06-05-2006

But, in this case, we are limited to a few days in the past or future. Another solution is Perl:

$ Perl-e 'use POSIX qw (strftime); print strftime "% a % B % e % H: % M: % S % Y",/localtime (time () -3600*24*2); 'tue May 2 14:59:41 2006

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.