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)
上一篇 2016-06-03 12:45
下一篇 2016-06-03 14:25

相关推荐

  • http加速器varnish

    一、web缓存概述       缓存,又称加速器,用于加速运行速度较快的设备与较慢设备之间的通信。基于程序的运行具有局部性特征其能实现加速的功能:       时间局部性:一个数据被访问之后,在随后较短的时间内有可能被访问。   &nbsp…

    2016-11-18
  • find 详解

    find 命令基本用法:         find pathname [opotions] [-print | -exec | -ok …] 1、find 基本参数:         pa…

    Linux干货 2016-12-26
  • Linux 第三天: (07月26日) Linux使用帮助

    Linux 第三天: (07月26日) Linux使用帮助         whatis 显示命令的简短描述makewhatis centos6 制作数据库mandb centos7 制作数据库 help COMMAND 内部命令man bash 内部命令COMMAND –help -h 外部命令man C…

    Linux干货 2016-08-08
  • Linux平台的4个最佳开源代码编辑器

    原文出处: Abhishek   译文出处:Linux中国 su-kaiyao   正在寻找Linux平台最棒的代码编辑器?如果你询问那些很早就玩Linux的人,他们会回答是Vi, Vim, Emacs, Nano等。但是,我今天不讨论那些。我将谈论一些新时代尖端、漂亮、时髦而且十分强大, 功能丰富…

    Linux干货 2015-03-02
  • bash脚本基础

    一,概述 shell脚本 程序:指令+数据 程序编程风格: 过程式:以指令为中心,数据服务于指令 对象式:以数据为中心,指令服务于数据 shell程序:提供了编程能力,解释执行 编程逻辑处理方式: 顺序执行 循环执行 选择执行 shell编程:过程式、解释执行 编程语言的基本结构: 数据存储:变量、数组 表达式: a + b 语句:if shell脚本是包含…

    Linux干货 2016-08-19
  • grub详解

    grub详解 1、GRUB(Boot Loader): grub:grub 0.x:grub1 legacy传统的版本 grub 1.x:grub2 grub legacy: 第1阶段:mbr 第1.5阶段:mbr之后的扇区中,让第一阶段中的boot loader能识别第二阶段所在分区上的文件系统 第2阶段:磁盘分区(/boot/grub/) 配置文件/et…

    2017-09-03