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

相关推荐

  • 强大的文本处理工具:vim编辑器

    一:引言 系统管理员的重要工作就是修改与设置某些软件的重要配置文件,而vim作为vi编辑器的升级版本,不仅能够以不同颜色来显示文字内容,还能够进行诸如shell脚本、C等程序的编写,所以,它还是一个程序编辑器,接下来,就让我们一起来看看vim的有哪些好玩的用法和特征。 二:vim三种模式及其常见用法 虽然vim有非常庞大甚至说它复杂也不为过的功能体系,但用结…

    2017-08-05
  • Linux基础知识(五)-文件查找命令find

    对grep 和 find 命令的操作 1、显示当前系统上root、fedora或user1用户的默认shell; 2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello(); 3、使用echo命令输出一个路径,使用grep取出其基名; 4、找出ifconfig命令结果中的1-255之间数字; 5、写一个…

    Linux干货 2016-10-24
  • 文件权限解析

    文件权限其实就是用户和用户组对文件或目录进行操作的权力。 文件的属性           上图中显示详细信息文件的详细属性,以最后一行为例从左向右依次说明:     1、drwxr-xr-x.    …

    2015-03-23
  • 笔记三、如何在VMWare Workstation中安装CentOS 7

    一、准备工作     1.1 安装VMWare WorkStatrion     1.2 准备好CentOS 7 镜像包     http://www.centoscn.com/CentosSoft/iso/    CenOS7下载地址 二…

    2017-02-23
  • Linux的命令使用格式

    ◆Linux命令格式:command [options]  [arguments]command:命令options:  –单词   或   -单字如: ls –allequ      ls -als -a -b -cequ&…

    Linux干货 2016-10-31
  • nginx及I/O介绍原理

    上课笔记

    2018-03-12