在Linux中,时间分为两种:1;使用date命令 显示系统时间,2 使用clock 或 hwclock 显示硬件时间
系统时间和硬件时间会出现不同步的现象。
man命令=manual=命令手册
下面主要说下date的使用方法:
1 直接使用date命令查看当前时间:
[root@bogon ~]#
[root@bogon ~]# date
Thu Dec 8 20:36:21 CST 2016
2 使用date命令修改时间
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
月日小时分钟年.秒
# date 1208204516.30
3:格式:
%% 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) 显示当前时间
例如:
# date +%c
Thu 08 Dec 2016 09:08:50 PM CST
%C century; like %Y, except omit last two digits (e.g., 20) 显示世纪:如显示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 以年月日的格式显示 2016-12-8
%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, space padded ( 0..23); same as %_H
%l hour, space padded ( 1..12); same as %_I
%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 表示PM
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM) 12小时制显示时间
%R 24-hour hour and minute; same as %H:%M 24小时制显示小时:分钟
%s seconds since 1970-01-01 00:00:00 UTC 从1970年1月1日到今天的秒数
%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 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)
#date +%D ---按照月/日/年 的格式显示日期
12/08/16
# date +%M ---显示当前分钟
#date +%m---显示当月月份
#date +%Y --- 显示四位数年份 (2016)
#date +%y---- 显示年份后两位(16)
#date +"今年是%Y"---- 显示为--今年是2016
#date +%Y-%m-%d 按格式 年-月-日 显示
#date +%H:%M:%S
#hwclock -w 表示把系统时间同步到硬件
#hwclock -s 表示把硬件时间同步到系统