1.功能描述:
显示和设置系统的时间及日期
2.格式
date 选项 字符串
3.举例
1. -s 设置系统的时间及日期
[root@nn ~]# date -s "2016-05-31 15:06"
2016年 05月 31日 星期二 15:06:00 CST
2.-d 显示字符串里的时间及日期,not now
[root@nn ~]# date -d "2016-5-30"
2016年 05月 30日 星期一 00:00:00 CST
[root@nn ~]# date -d "2016-5-30 12:03"
2016年 05月 30日 星期一 12:03:00 CST
3. -u 显示或设置世界标准时间 print or set Coordinated Universal Time
[root@nn zhangna]# date -u
2016年 05月 31日 星期二 07:15:00 UTC
[root@nn zhangna]# date
2016年 05月 31日 星期二 15:15:03 CST
需要特别说明的是,只有超级用户才能用date命令设置时间,一般用户只能用date命令显示时间。
例1:用指定的格式显示时间。
$ date '+This date now is =>%x ,time is now =>%X ,thank you !'
This date now is =>11/12/99 ,time is now =>17:53:01,thank you !
例2:用预定的格式显示当前的时间。
# date
Fri Nov 26 15:20:18 CST 1999
例3:设置时间为下午14点36分。
# date -s 14:36:00
Fri Nov 26 14:15:00 CST 1999
例4:设置时间为1999年11月28号。
# date -s 991128
Sun Nov 28 00:00:00 CST 1999
实例:设置时间伟2008年8月8号12:00
# date -s "2008-08-08 12:00:00"
修改完后,记得执行clock -w,把系统时间写入CMOS
时间的表示形式:
%% 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)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..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
%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)
%Y year
%z +hhmm numeric timezone (e.g., -0400)
%:z +hh:mm numeric timezone (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)