[关闭]
@mrz1 2018-01-01T14:15:31.000000Z 字数 4705 阅读 660

linux-时间

笔记

主要内容

  • 有关时间的命令

date命令使用

  1. NAME
  2. date - print or set the system date and time 打印或者设置日期
  3. SYNOPSIS
  4. date [OPTION]... [+FORMAT] 打印功能
  5. date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] 设置日期
  6. DESCRIPTION
  7. Display the current time in the given FORMAT, or set the system date.
  8. Mandatory arguments to long options are mandatory for short options too.
  9. -d, --date=STRING
  10. display time described by STRING, not 'now'
  11. -f, --file=DATEFILE
  12. like --date once for each line of DATEFILE
  13. -I[TIMESPEC], --iso-8601[=TIMESPEC]
  14. output date/time in ISO 8601 format. TIMESPEC='date' for date only
  15. (the default), 'hours', 'minutes', 'seconds', or 'ns' for date and time
  16. to the indicated precision.
  17. -r, --reference=FILE
  18. display the last modification time of FILE
  19. -R, --rfc-2822
  20. output date and time in RFC 2822 format. Example: Mon, 07 Aug 2006
  21. 12:34:56 -0600
  22. --rfc-3339=TIMESPEC
  23. output date and time in RFC 3339 format. TIMESPEC='date', 'seconds',
  24. or 'ns' for date and time to the indicated precision. Date and time
  25. components are separated by a single space: 2006-08-07 12:34:56-06:00
  26. -s, --set=STRING
  27. set time described by STRING
  28. -u, --utc, --universal
  29. print or set Coordinated Universal Time (UTC)
  30. --help display this help and exit
  31. --version
  32. output version information and exit
  33. FORMAT controls the output. Interpreted sequences are:
  34. %% a literal % 显示百分号
  35. %a locale's abbreviated weekday name (e.g., Sun) 显示星期简单名字
  36. %A locale's full weekday name (e.g., Sunday) 显示星期长名字
  37. %b locale's abbreviated month name (e.g., Jan)显示月份短名字
  38. %B locale's full month name (e.g., January) 显示月份长名字
  39. %c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
  40. %C century; like %Y, except omit last two digits (e.g., 20)显示世纪
  41. %d day of month (e.g., 01)显示日
  42. %D date; same as %m/%d/%y 月日年
  43. %e day of month, space padded; same as %_d 带空格填充的月
  44. %F full date; same as %Y-%m-%d 年月日
  45. %g last two digits of year of ISO week number (see %G)
  46. %G year of ISO week number (see %V); normally useful only with %V
  47. %h same as %b
  48. %H hour (00..23) 24小时
  49. %I hour (01..12) 12小时
  50. %j day of year (001..366)年内日
  51. %k hour, space padded ( 0..23); same as %_H 带空格的24小时
  52. %l hour, space padded ( 1..12); same as %_I 带空格的12小时
  53. %m month (01..12) 月
  54. %M minute (00..59)分钟
  55. %n a newline 空行
  56. %N nanoseconds (000000000..999999999)
  57. %p locale's equivalent of either AM or PM; blank if not known 上午下午
  58. %P like %p, but lower case 小写的上下午
  59. %r locale's 12-hour clock time (e.g., 11:11:04 PM)
  60. %R 24-hour hour and minute; same as %H:%M 小时和分钟的
  61. %s seconds since 1970-01-01 00:00:00 UTC 总秒数从70年开始
  62. %S second (00..60)秒
  63. %t a tab 制表符
  64. %T time; same as %H:%M:%S 时分秒
  65. %u day of week (1..7); 1 is Monday 指定日期在一周中是第几天
  66. %U week number of year, with Sunday as first day of week (00..53) 指定日期在这年中是第几周
  67. %V ISO week number, with Monday as first day of week (01..53)
  68. %w day of week (0..6); 0 is Sunday 指定日期在一周中是第几天
  69. %W week number of year, with Monday as first day of week (00..53)
  70. %x locale's date representation (e.g., 12/31/99)
  71. %X locale's time representation (e.g., 23:13:48)
  72. %y last two digits of year (00..99) 2位数字的年
  73. %Y year 年
  74. %z +hhmm numeric time zone (e.g., -0400)
  75. %:z +hh:mm numeric time zone (e.g., -04:00)
  76. %::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
  77. %:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
  78. %Z alphabetic time zone abbreviation (e.g., EDT)
  79. By default, date pads numeric fields with zeroes. The following optional
  80. flags may follow '%':
  81. - (hyphen) do not pad the field
  82. _ (underscore) pad with spaces
  83. 0 (zero) pad with zeros
  84. ^ use upper case if possible
  85. # use opposite case if possible

date显示和修改日期

  1. [root@zhang ~]# date '+%Y-%m-%d %H:%M:%S'
  2. 2017-11-06 09:15:34
  3. [root@zhang ~]# date 120108022012.59
  4. Sat Dec 1 08:02:59 CST 2012
  5. [root@zhang ~]# date '+%Y-%m-%d %H:%M:%S'
  6. 2012-12-01 08:03:23

时钟的修改

  1. [root@zhang ~]# hwclock --hctosys # hc to sys 硬件去修改系统
  2. [root@zhang ~]# hwclock --systohc # sys to hc 系统去修改硬件

日历的查看

  1. [root@zhang ~]# cal
  2. November 2017
  3. Su Mo Tu We Th Fr Sa
  4. 1 2 3 4
  5. 5 6 7 8 9 10 11
  6. 12 13 14 15 16 17 18
  7. 19 20 21 22 23 24 25
  8. 26 27 28 29 30
  9. $ cal -y 查看日历
  10. $ cal 9 1752 特殊的日期
  11. [root@zhang ~]# cal 2016
  12. 2016
  13. January February March
  14. Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
  15. 1 2 1 2 3 4 5 6 1 2 3 4 5
  16. 3 4 5 6 7 8 9 7 8 9 10 11 12 13 6 7 8 9 10 11 12
  17. 10 11 12 13 14 15 16 14 15 16 17 18 19 20 13 14 15 16 17 18 19
  18. 17 18 19 20 21 22 23 21 22 23 24 25 26 27 20 21 22 23 24 25 26
  19. 24 25 26 27 28 29 30 28 29 27 28 29 30 31
  20. 31
  21. April May June
  22. Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
  23. 1 2 1 2 3 4 5 6 7 1 2 3 4
  24. 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
  25. 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
  26. 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
  27. 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
  28. July August September
  29. Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
  30. 1 2 1 2 3 4 5 6 1 2 3
  31. 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
  32. 10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
  33. 17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
  34. 24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
  35. 31
  36. October November December
  37. Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
  38. 1 1 2 3 4 5 1 2 3
  39. 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
  40. 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
  41. 16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
  42. 23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
  43. 30 31
  1. $ echo `date +%s`/3600/24|bc 查看天数
  2. $ date -d '2 days ago' //显示2天以前的时间
  3. $ date -d '60 second ago' //显示60秒以前的时间
  4. $ date -d '3 months 1 day' //显示3月零1天以后的时间
  5. $ date -d '25 Dec' +%j //显示12月25日在当年的哪一天
  6. $ date -d '1970-01-01 00:00:30 +0000' +%s //自UTC 时间 1970-01-01 00:00:00 以来所经过的秒数
  7. $ date -s '2019-08-19 12:12:12' 设置时间date "+%Y-%m-%d %H:%m:%S"
  8. $ clock -w,把系统时间写入CMOS
  9. $ sleep 3 等待3
  10. $ date +%Y-%m-%d\ %H:%M:%S 2017-11-10 21:47:14
  11. $ timedatectl list-timezones 查看所有支持的时间列表contos7 tzselect
  12. $ shutdown -r +1 1分钟周关机
  13. $ shutdown -r 10:05 指定时间
  14. $ shutdown -c 取消关机
  15. $ shutdown now 马上关机
  16. $ shutdown -h +100 "系统十分钟关机"
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注