Linuxdate-d parameter usage

Source: Internet
Author: User
Tags month name
Linuxdate-d parameter usage * Toprintthedateofthedaybeforeyesterday: www.2cto. comdate -- date & amp; #39; 2 daysago & amp; #39; * Toprintthedateofthedaythreemonths... linux date-d parameter usage * To print the date of the day before yesterday: www.2cto.com date -- date = '2 days ago '* To print the date of the day three months and one day hence: date -- date = '3 months 1 day' * To print the day of year of Christmas in the current year: date -- date = '25 Dec '+ % j * To print the current full month name and the day of the month: date '+ % B % d' But this may not be what you want because for the first nine days of the month, the '% d' expands to a zero-padded two-digit field, for example 'date-d 1may' + % B % d' will print 'may 01 '. * To print a date without the leading zero for one-digit days of the month, you can use the (GNU extension) '-'flag to suppress the padding altogether: date-d 1may' + % B %-d * To print the current date and time in the format required by using non-GNU versions of 'date' when setting the system clock: date + % m % d % H % M % Y. % S * To set the system clock forward by two minutes: date -- set = '+ 2 minutes' * To print the date in RFC 2822 format, use 'date -- rfc-2822 '. here is some example output: Fri, 09 Sep 2005 13:51:39-0700 * To convert a date string to the number of seconds since the epoch (which is 00:00:00 UTC ), use the '-- date' option with the' % s' format. that can be useful in sorting and/or graphing and/or comparing data by date. the following command outputs the number of the seconds since the epoch for the time two minutes after the epoch: date -- date = '2017-01-01 00:02:00 + 100' + % s date -- date = '2017-01-01 00:02:00 + 100' + % s 1970 If you do not specify time zone information in the date string, 'date' uses your computer's idea of the time zone when interpreting the string. for example, if your computer's time zone is that of Cambridge, mascript usetts, which was then 5 hours (I. e ., 18,000 seconds) behind UTC: # local time zone used date -- date = '2017-01-01 00:02:00 '+ % s 1970 * If you're sorting or graphing dated data, your raw date values may be represented as seconds since the epoch. but few people can look at the date '200' and casually note "Oh, that's the first second of the year 946684800 in Greenwich, England. "date -- date = '1970-01-01 UTC '+ % s 2000 An alternative is to use the' -- UTC' ('-u') option. then you may omit 'utc' from the date string. although this produces the same result for '% s' and other format sequences, with a time zone offset different from zero, it wowould give a different result for zone-dependent formats like '% Z '. date-u -- date = 2000-01-01 + % s 946684800 To convert such an unwieldy number of seconds back to a more readable form, use a command like this: # local time zone used date-d '2017-01-01 UTC 1970 seconds' + "% Y-% m-% d % T % z" 946684800 19:00:00-0500 Often it is better to output UTC-relative date and time: date-u-d '2017-01-01 1970 seconds '+ "% Y-% m-% d % T % z" 2000-01-01 00:00:00 + 946684800
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.