Linux date command details

Source: Internet
Author: User
Tags current greenwich mean time iso 8601 iso 8601 format

Http://www.cnblogs.com/wllyy189/archive/2008/06/05/1214448.html

Usage:

Date [-u] [-D datestr] [-s datestr] [-- UTC] [-- Universal] [-- date = datestr] [-- set = datestr] [-- help] [-- version] [+ format] [mmddhhmm [[CC] YY] [. SS]
Note:
Date can be used to display or set the date and time of the system. In terms of display, you can set the format to be displayed. The format is set to a plus sign followed by several tags, the available tags are listed as follows:
Time:
%: Print %
% N: Next row
% T: Skip
% H: hour (00 .. 23)
% I: hour (01 .. 12)
% K: hour (0 .. 23)
% L: hour (1 .. 12)
% M: minute (00 .. 59)
% P: displays local am or PM
% R: direct display time (in 12-hour format: hh: mm: ss [AP] m)
% S: the number of seconds since January 1, 1970 00:00:00 UTC till now
% S: seconds (00 .. 61)
% T: direct display time (in 24-hour format)
% X: equivalent to % H: % m: % s
% Z: display the time zone
Date:
% A: The day of the week (Sun .. SAT)
% A: The day of the week (Sunday .. Saturday)
% B: Month (Jan .. dec)
% B: Month (January... December)
% C: Display date and time directly
% D: Day (01 .. 31)
% D: Display date directly (mm/DD/yy)
% H: Same as % B
% J: The day of the year (001 .. 366)
% M: Month (01 .. 12)
% U: Week (00 .. 53) of the year (the first day of the week on Sunday)
% W: The day of the week (0 .. 6)
% W: Week (00 .. 53) of the Year (Monday is the first day of the week)
% X: Display date directly (mm/DD/yy)
% Y: last two digits of the Year (00.99)
% Y: full year (0000 .. 9999)
If it does not start with a plus sign, the time is set, and the time format is mmddhhmm [[CC] YY] [. SS], where mm is the month, DD is the day, HH is the hour, mm is the minute, CC is the first two digits of the Year, YY is the second digit of the Year, SS is the second digit
Parameters:
-D datestr: display the time set in datestr (non-system time)
-- Help: displays auxiliary messages.
-S datestr: set the system time to the time set in datestr
-U: displays the current Greenwich Mean Time.
-- Version: displays the version number.
Example:
After the time is displayed, the line jumps and the current date is displayed:
Date' + % T % N % d'
Show month and number of days:
Date' + % B % d'
Display date and set time (12:34:56 ):
Date -- date '12: 34: 56'
Note:
If you do not want meaningless 0 values (for example,), you can insert the-symbol in the tag, for example, date '+ %-H: %-M: %-s will remove the meaningless 0 in the hour, minute, and second, as if the original 08:09:04 will change. In addition, you can set the system time only when you have the permission (such as root.

After you change the system time as root, remember to write the system time to CMOS using clock-w, in this way, the system time will continue to hold the latest correct value upon the next reboot.

 

Http://witmax.cn/linux-date.html

Display time is a commonly used command. It is often used to display date-related file names or times in shell scripts. The date command is used in both Linux and Windows.

Date command usage in Linux

    • Date [Option]… [+ Format]
    • Date [-u | -- UTC | -- Universal] [mmddhhmm [[CC] YY] [. SS]

 

Date Command Parameters

    • -D,-date = string: display the time specified by string
    • -F,-file = datefile, similar to the-date parameter, shows the time of each row in the datefile file.
    • -Itimespec,-iso-8601 [= timespec] displays date/time in ISO 8601 format. Timespec is one of the following values: "date" (only display date), "hours", "Minutes", and "senconds" (display time precision). The default value is "date ".
    • -R,-reference = file: displays the last modification time of the file.
    • -R,-the rfc-2822 displays time in RFC-2822 compatible Date Format
    • -S,-set = string is set to string
    • -U,-UTC,-Universal Display or set to Coordinated Universal Time Format

Date command output display format

  • % Characters %
  • % A abbreviation of a week (Sun .. SAT)
  • % A full name of the Week (Sunday .. Saturday)
  • % B (Jan .. dec)
  • % B full name of the month (January... December)
  • % C date and time (Sat Nov 04 12:02:33 est 1989)
  • % C Century (excluding the sum after 100) [00-99]
  • % D the day of the month (01 .. 31)
  • % D Date (mm/DD/yy)
  • % E the day of a month (1 .. 31)
  • % F date, same as % Y-% m-% d
  • % G year (yy)
  • % G year (YYYY)
  • % H is the same as % B
  • % H hour (00 .. 23)
  • % I hour (01 .. 12)
  • % J the day of the year (001 .. 366)
  • % K hour (0 .. 23)
  • % L hour (1 .. 12)
  • % M month (01 .. 12)
  • % M minutes (00 .. 59)
  • % N line feed
  • % N nanoseconds (000000000 .. 999999999)
  • % P am or PM
  • % P am or PM
  • % R 12-hour time (HH: mm: ss [AP] m)
  • % R 24-hour system time (HH: mm)
  • % S seconds starting from 00:00:00 UTC
  • % S seconds (00 .. 60)
  • % T Tab
  • % T in 24-hour format (HH: mm: SS)
  • % U day of the week (1 .. 7); 1 indicates Monday
  • % U the week of the year, and Sunday is the first day of the week (00 .. 53)
  • % V the week of the year. Monday is the first day of the week (01 .. 53)
  • % W the day of the week (0 .. 6); 0 indicates Sunday
  • % W the week of the year, and Monday is the first day of the week (00 .. 53)
  • % X date (mm/DD/yy)
  • % X time (% H: % m: % s)
  • % Y year (00 .. 99)
  • % Y year (1970 ...)
  • % Z RFC-2822 style numeric format Time Zone (-0500)
  • % Z Time Zone (e.g., EDT). If the time zone cannot be determined, it is null.

The following are some experiments for ease of understanding:

01020304050607080910111213141516171819202122232425262728293031323334353637383940414243444546474849 $ Date-d "23:00:01" Mon Nov 15 23:00:01 PST 2010. $ Date-d "2010/11/15" Mon Nov 15 23:00:02 PST 2010. $ Date-d "2010/11/15 T23: 0: 2" Mon Nov 15 08:00:02 PST 2010. $ $ Echo "2010-11-15 23:00:01"> date.txt $ Echo "2010/11/15 23:00:02"> date.txt $ Cat date.txt 23:00:01 2010/11/15 23:00:02 $ Date-F date.txt Mon Nov 15 23:00:01 PST 2010. Mon Nov 15 23:00:02 PST 2010. $ $ LS-l Total 4 -RW-r -- 1 znan Sybase 40 Nov 15 21:14 date.txt $ Date-r date.txt Mon Nov 15 21:14:36 PST 2010. $ $ Date-I 2010-11-15 $ Date-ihours 2010-11-15t21-0800 $ Date-iminutes 2010-11-15t21: 16-0800 $ Date-iseconds 2010-11-15t21: 16: 24-0800 $ $ Date-R Mon, 15 Nov 2010 21:47:08-0800 $ Date-u Tue Nov 16 05:47:13 UTC 2010 $ $ Date + "Today is % ." Today is Monday. $ Date + "Date: % B. % E, % G" Date: Nov. 15,201 0 $ Date + "Date: % B. % E, % G" Date: nov.15 and 2010 $ Date + "% x" 11/15/2010 09:50:21 $ Date + "% Y-% m-% d % H: % m: % s" 21:51:32 $ Date + "% Y-% m-% d % I: % m: % S % P" 09:51:55 $

 

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.