Latest web development tutorials

Linux date Command

Linux command Daquan Linux command Daquan

After Linux date command can be used to display or set the system date and time, and in the display, the user can set the format to be displayed in the format set as a plus access several tags, list tags which are available as follows:

Time aspects:

  • %: Print%
  • % N: the next line
  • % T: tabulator
  • % H: hour (00..23)
  • % I: hour (01..12)
  • % K: Hour (0..23)
  • % L: Hour (1..12)
  • % M: minute (00..59)
  • % P: Displays the local AM or PM
  • % R: direct display time (12-hour format hh: mm: ss [AP] M)
  • % S: From January 1, 1970 00:00:00 UTC by far the number of seconds
  • % S: seconds (00..61)
  • % T: direct display time (24-hour)
  • % X: equivalent to% H:% M:% S
  • % Z: Display time zone

Date of areas:

  • % A: day of the week (Sun..Sat)
  • % A: weekday (Sunday..Saturday)
  • % B: Month (Jan..Dec)
  • % B: Month (January..December)
  • % C: direct display date and time
  • % D: day (01..31)
  • % D: direct display date (mm / dd / yy)
  • % H:% b with
  • % J: The day of the year (001..366)
  • % M: month (01..12)
  • % U: The first few weeks of the year (00 .. 53) (with Sunday as the first day of the week the situation)
  • % W: the first few days of the week (0..6)
  • % W: The first few weeks of the year (00 .. 53) (with Monday as the first day of the week the situation)
  • % X: direct display date (mm / dd / yy)
  • % Y: the last two digits of the year (00.99)
  • % Y: full year (0000..9999)

If not as the beginning of a plus sign, it means you want to set the time, and the time format MMDDhhmm [[CC] YY] [. Ss], where MM is the month, DD is day, hh is hour, mm minutes, CC is Year two digits, YY is the year the last two digits, ss is seconds.

Access: All users.

When you do not want to appear 0:00 meaningless (for example, 1999/03/07), you can insert in the mark - symbol, such as date '+% - H:% - M:% - S' when will the minutes and seconds 0 to remove meaningless, like the original 08:09:04 becomes 8: 9: 4. In addition, only those who get permission (for example, root) to set the system time.

When you change the system time as root, remember to clock -w system time is written to CMOS, and reboot the system so that the next time will be the latest continuing hold the correct value.

grammar

date [-u] [-d datestr] [-s datestr] [--utc] [--universal] [--date=datestr] [--set=datestr] [--help] [--version] [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]

Parameter Description:

  • -d datestr: datestr display in the set time (non-system time)
  • --help: display auxiliary information
  • -s datestr: the system time is set in the time set datestr
  • -u: Displays the current Greenwich Mean Time
  • --version: display version number

Examples

Displays the current time

# date
三 5月 12 14:08:12 CST 2010
# date '+%c' 
2010年05月12日 星期三 14时09分02秒
# date '+%D' //显示完整的时间
05/12/10
# date '+%x' //显示数字日期,年份两位数表示
2010年05月12日
# date '+%T' //显示日期,年份用四位数表示
14:09:31
# date '+%X' //显示24小时的格式
14时09分39秒

According to their own output format

# date '+usr_time: $1:%M %P -hey'
usr_time: $1:16 下午 -hey

After the display time skip, and then display the current date

date '+%T%n%D'

Display the month and the number of days

date '+%B %d'

Displays the date and set time (12:34:56)

date --date '12:34:56'

Linux command Daquan Linux command Daquan