@mrz1
2018-01-01T14:15:31.000000Z
字数 4705
阅读 870
笔记
- 有关时间的命令
NAMEdate - print or set the system date and time 打印或者设置日期SYNOPSISdate [OPTION]... [+FORMAT] 打印功能date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] 设置日期DESCRIPTIONDisplay the current time in the given FORMAT, or set the system date.Mandatory arguments to long options are mandatory for short options too.-d, --date=STRINGdisplay time described by STRING, not 'now'-f, --file=DATEFILElike --date once for each line of DATEFILE-I[TIMESPEC], --iso-8601[=TIMESPEC]output date/time in ISO 8601 format. TIMESPEC='date' for date only(the default), 'hours', 'minutes', 'seconds', or 'ns' for date and timeto the indicated precision.-r, --reference=FILEdisplay the last modification time of FILE-R, --rfc-2822output date and time in RFC 2822 format. Example: Mon, 07 Aug 200612:34:56 -0600--rfc-3339=TIMESPECoutput date and time in RFC 3339 format. TIMESPEC='date', 'seconds',or 'ns' for date and time to the indicated precision. Date and timecomponents are separated by a single space: 2006-08-07 12:34:56-06:00-s, --set=STRINGset time described by STRING-u, --utc, --universalprint or set Coordinated Universal Time (UTC)--help display this help and exit--versionoutput version information and exitFORMAT controls the output. Interpreted sequences are:%% a literal % 显示百分号%a locale's abbreviated weekday name (e.g., Sun) 显示星期简单名字%A locale's full weekday name (e.g., Sunday) 显示星期长名字%b locale's abbreviated month name (e.g., Jan)显示月份短名字%B locale's full month name (e.g., January) 显示月份长名字%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)%C century; like %Y, except omit last two digits (e.g., 20)显示世纪%d day of month (e.g., 01)显示日%D date; same as %m/%d/%y 月日年%e day of month, space padded; same as %_d 带空格填充的月%F full date; same as %Y-%m-%d 年月日%g last two digits of year of ISO week number (see %G)%G year of ISO week number (see %V); normally useful only with %V%h same as %b%H hour (00..23) 24小时%I hour (01..12) 12小时%j day of year (001..366)年内日%k hour, space padded ( 0..23); same as %_H 带空格的24小时%l hour, space padded ( 1..12); same as %_I 带空格的12小时%m month (01..12) 月%M minute (00..59)分钟%n a newline 空行%N nanoseconds (000000000..999999999)%p locale's equivalent of either AM or PM; blank if not known 上午下午%P like %p, but lower case 小写的上下午%r locale's 12-hour clock time (e.g., 11:11:04 PM)%R 24-hour hour and minute; same as %H:%M 小时和分钟的%s seconds since 1970-01-01 00:00:00 UTC 总秒数从70年开始%S second (00..60)秒%t a tab 制表符%T time; same as %H:%M:%S 时分秒%u day of week (1..7); 1 is Monday 指定日期在一周中是第几天%U week number of year, with Sunday as first day of week (00..53) 指定日期在这年中是第几周%V ISO week number, with Monday as first day of week (01..53)%w day of week (0..6); 0 is Sunday 指定日期在一周中是第几天%W week number of year, with Monday as first day of week (00..53)%x locale's date representation (e.g., 12/31/99)%X locale's time representation (e.g., 23:13:48)%y last two digits of year (00..99) 2位数字的年%Y year 年%z +hhmm numeric time zone (e.g., -0400)%:z +hh:mm numeric time zone (e.g., -04:00)%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)%Z alphabetic time zone abbreviation (e.g., EDT)By default, date pads numeric fields with zeroes. The following optionalflags may follow '%':- (hyphen) do not pad the field_ (underscore) pad with spaces0 (zero) pad with zeros^ use upper case if possible# use opposite case if possible
date显示和修改日期
[root@zhang ~]# date '+%Y-%m-%d %H:%M:%S'2017-11-06 09:15:34[root@zhang ~]# date 120108022012.59Sat Dec 1 08:02:59 CST 2012[root@zhang ~]# date '+%Y-%m-%d %H:%M:%S'2012-12-01 08:03:23
时钟的修改
[root@zhang ~]# hwclock --hctosys # hc to sys 硬件去修改系统[root@zhang ~]# hwclock --systohc # sys to hc 系统去修改硬件
日历的查看
[root@zhang ~]# calNovember 2017Su Mo Tu We Th Fr Sa1 2 3 45 6 7 8 9 10 1112 13 14 15 16 17 1819 20 21 22 23 24 2526 27 28 29 30$ cal -y 查看日历$ cal 9 1752 特殊的日期[root@zhang ~]# cal 20162016January February MarchSu Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa1 2 1 2 3 4 5 6 1 2 3 4 53 4 5 6 7 8 9 7 8 9 10 11 12 13 6 7 8 9 10 11 1210 11 12 13 14 15 16 14 15 16 17 18 19 20 13 14 15 16 17 18 1917 18 19 20 21 22 23 21 22 23 24 25 26 27 20 21 22 23 24 25 2624 25 26 27 28 29 30 28 29 27 28 29 30 3131April May JuneSu Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa1 2 1 2 3 4 5 6 7 1 2 3 43 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 1110 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 1817 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 2524 25 26 27 28 29 30 29 30 31 26 27 28 29 30July August SeptemberSu Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa1 2 1 2 3 4 5 6 1 2 33 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 1010 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 1717 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 2424 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 3031October November DecemberSu Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa1 1 2 3 4 5 1 2 32 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 109 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 1716 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 2423 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 3130 31
$ echo `date +%s`/3600/24|bc 查看天数$ date -d '2 days ago' //显示2天以前的时间$ date -d '60 second ago' //显示60秒以前的时间$ date -d '3 months 1 day' //显示3月零1天以后的时间$ date -d '25 Dec' +%j //显示12月25日在当年的哪一天$ date -d '1970-01-01 00:00:30 +0000' +%s //自UTC 时间 1970-01-01 00:00:00 以来所经过的秒数$ date -s '2019-08-19 12:12:12' 设置时间date "+%Y-%m-%d %H:%m:%S"$ clock -w,把系统时间写入CMOS$ sleep 3 等待3秒$ date +%Y-%m-%d\ %H:%M:%S 2017-11-10 21:47:14$ timedatectl list-timezones 查看所有支持的时间列表contos7 tzselect$ shutdown -r +1 1分钟周关机$ shutdown -r 10:05 指定时间$ shutdown -c 取消关机$ shutdown now 马上关机$ shutdown -h +100 "系统十分钟关机"