@mrz1
2018-01-01T14:15:31.000000Z
字数 4705
阅读 752
笔记
- 有关时间的命令
NAME
date - print or set the system date and time 打印或者设置日期
SYNOPSIS
date [OPTION]... [+FORMAT] 打印功能
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] 设置日期
DESCRIPTION
Display 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=STRING
display time described by STRING, not 'now'
-f, --file=DATEFILE
like --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 time
to the indicated precision.
-r, --reference=FILE
display the last modification time of FILE
-R, --rfc-2822
output date and time in RFC 2822 format. Example: Mon, 07 Aug 2006
12:34:56 -0600
--rfc-3339=TIMESPEC
output date and time in RFC 3339 format. TIMESPEC='date', 'seconds',
or 'ns' for date and time to the indicated precision. Date and time
components are separated by a single space: 2006-08-07 12:34:56-06:00
-s, --set=STRING
set time described by STRING
-u, --utc, --universal
print or set Coordinated Universal Time (UTC)
--help display this help and exit
--version
output version information and exit
FORMAT 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 optional
flags may follow '%':
- (hyphen) do not pad the field
_ (underscore) pad with spaces
0 (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.59
Sat 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 ~]# cal
November 2017
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
$ cal -y 查看日历
$ cal 9 1752 特殊的日期
[root@zhang ~]# cal 2016
2016
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 1 2 3 4 5
3 4 5 6 7 8 9 7 8 9 10 11 12 13 6 7 8 9 10 11 12
10 11 12 13 14 15 16 14 15 16 17 18 19 20 13 14 15 16 17 18 19
17 18 19 20 21 22 23 21 22 23 24 25 26 27 20 21 22 23 24 25 26
24 25 26 27 28 29 30 28 29 27 28 29 30 31
31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 7 1 2 3 4
3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 1 2 3
3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 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 "系统十分钟关机"