Common shell date methods

Source: Internet
Author: User
Tags iso 8601 iso 8601 format month name rfc

Obtain the time string in Linux
Command date
# Output the current time of 23 days in the format of yyyymmdd
$ Date + % Y % m % d -- date = '23 days ago'

$ Date-u
Thu Sep 28 09:32:04 UTC 2006

$ Date-R
Thu, 28 Sep 2006 17:32:28 + 0800

# Testing one thousandth of a second
$ Date + '% Y % m % d % H: % m: % S. % n'; date + '% Y % m % d % H: % m: % S. % n'; date + '% Y % m % d % H: % m: % S. % n'; date + '% Y % m % d % H: % m: % S. % N'
20060928 17:44:20. 906805000
20060928 17:44:20. 909188000
20060928 17:44:20. 911535000
20060928 17:44:20. 913886000

Date reference
$ Date -- Help
Usage: Date [Option]... [+ format]
Or: Date [-u | -- UTC | -- Universal] [mmddhhmm [[CC] YY] [. SS]
Display the current time in the given format, or set the system date.

-D, -- date = string display time described by string, not 'now'
# Such as 'n' days ago | 1 month ago | N years ago'
-F, -- file = datefile like -- date once for each line of datefile
-Itimespec, -- iso-8601 [= timespec] Output date/time in ISO 8601 format.
Timespec = 'date' for date only,
'Urs', 'minutes ', or 'seconds' for date and
Time to the indicated precision.
-- Iso-8601 without timespec defaults to 'date '.
-R, -- reference = file display the last modification time of File
-R, -- rfc-2822 output RFC-2822 compliant date string
-S, -- set = string set time described by string
-U, -- UTC, -- Universal print or set Coordinated Universal Time
-- Help display this help and exit
-- Version output version information and exit

Format controls the output. The only valid option for the second form
Specifies Coordinated Universal Time. interpreted sequences are:

% Output % sign a literal %
% A the abbreviation of the week for the current domain locale's abbreviated weekday name (Sun .. SAT)
% A indicates that locale's full weekday name and variable length (Sunday .. Saturday) are all written for the current domain in the week)
% B the abbreviation of the month in the current domain locale's abbreviated month name (Jan... dec)
% B full month name of the current domain locale's full month name, variable length (January... December)
% C default time format of the current domain locale's date and time (Sat Nov 04 12:02:33 est 1989)
% C n Centennial Century (year divided by 100 and truncated to an integer) [00-99]
Day of month (01 .. 31) of % d)
% D short time format date (mm/DD/yy)
% E short format day of month, blank padded (1 .. 31)
% F file time format same as % Y-% m-% d
% G the 2-digit year corresponding to the % v week number
% G the 4-digit year corresponding to the % v week number
% H same as % B
% H hour in the 24-hour format (00 .. 23)
% I hour of 12 hour (01 .. 12)
% J day of year (001 .. 366) of the year)
% K short format hour (0 .. 23)
% L hour (1 .. 12) in 12-hour short format)
% M double-digit month (01 .. 12)
% M dual-bit minute (00 .. 59)
% N wrap a newline
% N 000000000 s nanoseconds (999999999)
% P upper-case current domain upper-afternoon indication locale's upper case am or PM indicator (blank in upper Locales)
% P upper-afternoon indication of the current domain in lower case locale's lower case am or PM indicator (blank in lower Locales)
% R 12-hour time representation (hour: minute: Second, double-digit) time, 12-hour (HH: mm: ss [AP] m)
% R 24-hour time representation (hour: minute, double digit) time, 24-hour (HH: mm)
% S seconds from basic time 00:00:00 to current time seconds since '00: 00: 00 UTC '(a GNU extension)
% S dual-bit second (00 .. 60); the 60 is necessary to accommodate a leap second
% T horizontal tab (Tab) a horizontal Tab
% T 24-hour time indicates time, 24-hour (HH: mm: SS)
% U indicates the day of the week (from Monday to Monday) of Week (1 .. 7); 1 represents Monday
% U week of the year Sunday is the start week number of year with Sunday as first day of week (00 .. 53)
% V The week Monday of the year is the start week number of year with Monday as first day of week (01 .. 53)
% W the day of the week Sunday starts 0-6 days of week (0 .. 6); 0 represents Sunday
% W week of the year Monday is the start week number of year with Monday as first day of week (00 .. 53)
% X local Date Format locale's date representation (mm/DD/yy)
% X local time format locale's time representation (% H: % m: % s)
Last two digits of year (00 .. 99) of % Y)
% Y year Year (1970 ...)
% Z RFC-2822 Standard Time Format representation of the domain RFC-2822 style numeric timezone (-0500) (a nonstandard extension)
% Z Time Zone (e.g., EDT), or nothing if no time zone is determinable

By default, date pads numeric fields with zeroes. GNU date recognizes
The following modifiers between '%' and a numeric directive.

'-' (Hyphen) do not pad the field
'_' (Underscore) pad the field with spaces

Http://websir.blogspot.com/2006/09/shelldate.html

Report Bugs .


Author
Flying. frivolous


Time:
AM






 









Tags:
Date,
Shell

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.