Examples of gnu date

xiaoxiao2021-03-06  62

original:

http://www.labri.fr/perso/~strandh/teaching/usi/common/sh-utils/sh-utils_65.html

Author: David MacKenzie et al.

Examples of Date

Here Are A Few Examples. Also See The Documentation for The `-d 'Option In The Previous Section.

To print the date of the day before yesterday: 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 Day Day D '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 The Padding AltoGether. Date -D = 1MAY' % B% - D '

TO Print The Current Date and Time In The Format Required by Many 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 The Format Specified by RFC-822, Use `Date - RFC '. I Just Did and Saw This: Mon, 25 Mar 1996 23:34:17 -0600

TO Convert a date string to the number of seconds since the epoch (Which IS 1970-01-01 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 one second later than the epoch, but in time zone five hours later (Cambridge, Massachusetts), thus a Total of FIVE Hours: Date --Date = '1970-01-01 00:00:01 UTC 5 Hours' % S18001

.. Suppose you had not specified time zone information in the example above Then, date would have used your computer's idea of ​​the time zone when interpreting the string Here's what you would get if you were in Greenwich, England: # local time zone used

Date --Date = '1970-01-01 00:00:01' % s

1

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 `946684800 'and casually note" Oh, that's the first second of the year 2000. " Date --date = '2000-01-01 UTC' % S

946684800

TO Convert Such An Unwieldy Number of Seconds Back to A More Readable Form, Use A Command Like this: Date -D '1970-01-01 946684800 Sec' "% Y-% M-% D% T% Z"

2000-01-01 00:00:00 0000

转载请注明原文地址:https://www.9cbs.com/read-120612.html

New Post(0)