linux时间

linux有两个时间:

    系统时间和硬件时间

系统时间:


最简单的使用date命令显示当前系统的时间,命令行输入date。

# date

Thu Jun  2 17:11:48 CST 2016

date的具体使用方式:

    1. date格式显示:date [OPTION]… [+FORMAT]

参考如下参数,使用方式例如:

# date +%y

16

# date +%y%m%d

160602

# date +%y%m%d%H%M%S

160602163503

如上例子一般用在自动备份时,使备份文件的名字上加上日期和时间以便查看。其他格式使用方法类似

格式中和可以加入其他字符和符号,例如:

# date +%y-%m-%d

16-06-02

# date +%yY-%mM-%dD

16Y-06M-02D

       %%     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, 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

       %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 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)

    2. 时间设置:date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]

先解释一下后面部分

[MMDDhhmm[[CC]YY][.ss]]

 月日时分  年     .秒

其中年和秒可以省略

例如:

date 06021712

设定时间为6月2日17点12分

date 0602171216.30 等价于date 060217122016.30

设定时间为16年6月2日17点12分30秒

硬件时间:


    首先思考一个问题,为什么linux关机后时间依然在走?电脑的主板上有一块电池为主板的晶体振荡器可保证主板上的时间在系统关闭之后依然再走,下次开机时系统时间就读取硬件时钟作为系统的时间。

   这里还需要考虑一个问题,而硬件时间和系统时间是单独走的。上面提到的date修改的是系统时间,但不能同步到硬件时间,所以关机之后系统时间失效,此时如何让硬件时间同步系统时间,这个就需要一个命令hwclock

hwlcock -w 

如果需要将硬件时间同步到系统时间也是可以的:

hwlcock -s

原创文章,作者:Net20_天意,如若转载,请注明出处:http://www.178linux.com/17378

(0)
Net20_天意Net20_天意
上一篇 2016-06-03 12:46
下一篇 2016-06-03 12:46

相关推荐

  • 基于mysql的数据库分析系统(rsyslog)

    rsyslog:日志收集和存储系统 1.事件在电脑中的日志记录格式为:     日期时间 主机 进程[pid]:事件内容 2.rsyslog的特性:     多线程;     UDP,TCP,SSL/TLS,RELP; &nbsp…

    Linux干货 2016-10-23
  • Linux基础知识(六)

    本问主要讲述Linux的基础知识,具体包一下内容: 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; cp /etc/rc.d/rc.sysinit /tmp sed "s/^[[:space:]]\?/#/g" /tmp/rc.sysini…

    Linux干货 2016-10-30
  • 脚本小练习

    1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。                            …

    Linux干货 2016-08-15
  • 软件包管理–rpm、yum

    rpm软件包管理,rpm命令的使用。yum命令使用,yum源的搭建,网络yum源的搭建方法。编译安装http

    Linux干货 2017-12-03
  • 第四周

    第四周blog 第四周blog 1 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 cp -r /etc/skel /home/tuser1 ; chmod -R go-r /home/tuser…

    Linux干货 2016-12-23
  • LVS-fwm&persistence

    Evernote Export 1、LVS-fwm fwm:FireWall Mark        在netfilter上给报文打标记;mangle表;        ipvsadm -A|E -t|u|f service-address [-s scheduler] &nbs…

    Linux干货 2016-12-01