linux: date 命令的用法

发布时间 2023-09-10 00:39:42作者: lnlidawei

linux: date 命令的用法

 

 

 

 

一、date  命令的用法

  1 [wit@fedora null]$ date "+%Y-%m-%d"
  2 2023-09-10
  3 [wit@fedora null]$ 
  4 [wit@fedora null]$ 
  5 [wit@fedora null]$ date --help
  6 Usage: date [OPTION]... [+FORMAT]
  7   or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
  8 Display date and time in the given FORMAT.
  9 With -s, or with [MMDDhhmm[[CC]YY][.ss]], set the date and time.
 10 
 11 Mandatory arguments to long options are mandatory for short options too.
 12   -d, --date=STRING          display time described by STRING, not 'now'
 13       --debug                annotate the parsed date,
 14                               and warn about questionable usage to stderr
 15   -f, --file=DATEFILE        like --date; once for each line of DATEFILE
 16   -I[FMT], --iso-8601[=FMT]  output date/time in ISO 8601 format.
 17                                FMT='date' for date only (the default),
 18                                'hours', 'minutes', 'seconds', or 'ns'
 19                                for date and time to the indicated precision.
 20                                Example: 2006-08-14T02:34:56-06:00
 21   --resolution               output the available resolution of timestamps
 22                                Example: 0.000000001
 23   -R, --rfc-email            output date and time in RFC 5322 format.
 24                                Example: Mon, 14 Aug 2006 02:34:56 -0600
 25       --rfc-3339=FMT         output date/time in RFC 3339 format.
 26                                FMT='date', 'seconds', or 'ns'
 27                                for date and time to the indicated precision.
 28                                Example: 2006-08-14 02:34:56-06:00
 29   -r, --reference=FILE       display the last modification time of FILE
 30   -s, --set=STRING           set time described by STRING
 31   -u, --utc, --universal     print or set Coordinated Universal Time (UTC)
 32       --help        display this help and exit
 33       --version     output version information and exit
 34 
 35 FORMAT controls the output.  Interpreted sequences are:
 36 
 37   %%   a literal %
 38   %a   locale's abbreviated weekday name (e.g., Sun)
 39   %A   locale's full weekday name (e.g., Sunday)
 40   %b   locale's abbreviated month name (e.g., Jan)
 41   %B   locale's full month name (e.g., January)
 42   %c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)
 43   %C   century; like %Y, except omit last two digits (e.g., 20)
 44   %d   day of month (e.g., 01)
 45   %D   date; same as %m/%d/%y
 46   %e   day of month, space padded; same as %_d
 47   %F   full date; like %+4Y-%m-%d
 48   %g   last two digits of year of ISO week number (see %G)
 49   %G   year of ISO week number (see %V); normally useful only with %V
 50   %h   same as %b
 51   %H   hour (00..23)
 52   %I   hour (01..12)
 53   %j   day of year (001..366)
 54   %k   hour, space padded ( 0..23); same as %_H
 55   %l   hour, space padded ( 1..12); same as %_I
 56   %m   month (01..12)
 57   %M   minute (00..59)
 58   %n   a newline
 59   %N   nanoseconds (000000000..999999999)
 60   %p   locale's equivalent of either AM or PM; blank if not known
 61   %P   like %p, but lower case
 62   %q   quarter of year (1..4)
 63   %r   locale's 12-hour clock time (e.g., 11:11:04 PM)
 64   %R   24-hour hour and minute; same as %H:%M
 65   %s   seconds since the Epoch (1970-01-01 00:00 UTC)
 66   %S   second (00..60)
 67   %t   a tab
 68   %T   time; same as %H:%M:%S
 69   %u   day of week (1..7); 1 is Monday
 70   %U   week number of year, with Sunday as first day of week (00..53)
 71   %V   ISO week number, with Monday as first day of week (01..53)
 72   %w   day of week (0..6); 0 is Sunday
 73   %W   week number of year, with Monday as first day of week (00..53)
 74   %x   locale's date representation (e.g., 12/31/99)
 75   %X   locale's time representation (e.g., 23:13:48)
 76   %y   last two digits of year (00..99)
 77   %Y   year
 78   %z   +hhmm numeric time zone (e.g., -0400)
 79   %:z  +hh:mm numeric time zone (e.g., -04:00)
 80   %::z  +hh:mm:ss numeric time zone (e.g., -04:00:00)
 81   %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)
 82   %Z   alphabetic time zone abbreviation (e.g., EDT)
 83 
 84 By default, date pads numeric fields with zeroes.
 85 The following optional flags may follow '%':
 86 
 87   -  (hyphen) do not pad the field
 88   _  (underscore) pad with spaces
 89   0  (zero) pad with zeros
 90   +  pad with zeros, and put '+' before future years with >4 digits
 91   ^  use upper case if possible
 92   #  use opposite case if possible
 93 
 94 After any flags comes an optional field width, as a decimal number;
 95 then an optional modifier, which is either
 96 E to use the locale's alternate representations if available, or
 97 O to use the locale's alternate numeric symbols if available.
 98 
 99 Examples:
100 Convert seconds since the Epoch (1970-01-01 UTC) to a date
101   $ date --date='@2147483647'
102 
103 Show the time on the west coast of the US (use tzselect(1) to find TZ)
104   $ TZ='America/Los_Angeles' date
105 
106 Show the local time for 9AM next Friday on the west coast of the US
107   $ date --date='TZ="America/Los_Angeles" 09:00 next Fri'
108 
109 GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
110 Full documentation <https://www.gnu.org/software/coreutils/date>
111 or available locally via: info '(coreutils) date invocation'
112 [wit@fedora null]$ 
113 [wit@fedora null]$ 

 

 

 

 

二、参考资料:

  1、[wit@fedora null]$ date  --help