Linux系统时间

1、date命令用于查看以及修改Linux系统的时间,关于date命令的详细帮助文档如下

[root@localhost ~]# date --help

Usage: date [OPTION]... [+FORMAT]

or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

Display the current time in the given FORMAT, or set the system date.

 

-d, --date=STRING display time described by STRING, not `now'

-f, --file=DATEFILE like --date once for each line of DATEFILE

-r, --reference=FILE display the last modification time of FILE

-R, --rfc-2822 output date and time in RFC 2822 format.

Example: Mon, 07 Aug 2006 12:34:56 -0600

--rfc-3339=TIMESPEC output date and time in RFC 3339 format.

TIMESPEC=`date', `seconds', or `ns' for

date and time to the indicated precision.

Date and time components are separated by

a single space: 2006-08-07 12:34:56-06:00

-s, --set=STRING set time described by STRING

-u, --utc, --universal print or set Coordinated Universal Time

--help display this help and exit

--version output version information and exit

 

FORMAT controls the output. Interpreted sequences are:

 

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

 

By default, date pads numeric fields with zeroes.

The following optional flags may follow `%':

 

- (hyphen) do not pad the field

_ (underscore) pad with spaces

0 (zero) pad with zeros

^ use upper case if possible

# use opposite case if possible

 

After any flags comes an optional field width, as a decimal number;

then an optional modifier, which is either

E to use the locale's alternate representations if available, or

O to use the locale's alternate numeric symbols if available.

 

Report date bugs to bug-coreutils@gnu.org

GNU coreutils home page: <http://www.gnu.org/software/coreutils/>

General help using GNU software: <http://www.gnu.org/gethelp/>

For complete documentation, run: info coreutils 'date invocation'

date常用格式及参数说明

date +%F === date +%Y-%m-%d    显示年月日

[root@localhost ~]# date +%F

2018-04-13

[root@localhost ~]# date +%Y-%m-%d

2018-04-13

date +%T === date +%H-%M-%S    显示时分秒

[root@localhost ~]# date +%T

21:39:42

[root@localhost ~]# date +%H-%M-%S

21-39-49

date +%F\ %T    显示年月日时分秒

[root@localhost ~]# date +%F\ %T

2018-04-13 21:41:23

date +%y    显示两位年份

[root@localhost ~]# date +%y

18

date +%Y    显示四位年份

[root@localhost ~]# date +%Y

2018

date +%m     显示月份

[root@localhost ~]# date +%m

04

date+%M     显示分钟

[root@localhost ~]# date +%M

42

date +%d     显示日

[root@localhost ~]# date +%d

13

date+%p或%P     显示出AM(am)或PM(pm)

[root@localhost ~]# date +%P

pm

[root@localhost ~]# date +%p

PM

date +%u     显示周几

[root@localhost ~]# date +%u

5

date +%H     小时24小时制(00~23)

[root@localhost ~]# date +%H

21

date +%I     小时12小时制(01~12)

[root@localhost ~]# date +%l

9

date+ %j     显示一年的第几天

[root@localhost ~]# date +%j

103

date+%W    显示一年的第几个星期

[root@localhost ~]# date +%W

15

date -d '-3day'    显示前三天的日期

[root@localhost ~]# date -d '-3day'

Tue Apr 10 21:45:46 CST 2018

date -s '20180401 08:20:00'    设置时间

[root@localhost ~]# date -s '20180401 08:20:00'

Sun Apr 1 08:20:00 CST 2018

 

2、同步时间命令ntpdate

ntp === network time protocol网络时间协议

利用时间服务器(阿里云等),也可以将此命令添加到定时任务中,让Linux系统定时同步时间

ntpdate ntp1.aliyun.com

ntpdate ntp2.aliyun.com

ntpdate ntp3.aliyun.com

ntpdate ntp4.aliyun.com

ntpdate ntp5.aliyun.com

ntpdate ntp6.aliyun.com

 

3、cal 显示日历

-1 显示一个月的月历

-3 显示系统前一个月,当前月,下一个月的月历

-s 显示星期天为一个星期的第一天,默认的格式

-m 显示星期一为一个星期的第一天

-j 显示在当年中的第几天(一年日期按天算,从1月1号算起,默认显示当前月在一年中的天数)

-y 显示当前年份的日历的所有年月份

[root@localhost ~]# cal -y

2018

 

January February March

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 1 2 3 1 2 3

7 8 9 10 11 12 13 4 5 6 7 8 9 10 4 5 6 7 8 9 10

14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17

21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24

28 29 30 31 25 26 27 28 25 26 27 28 29 30 31

 

April May June

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 7 1 2 3 4 5 1 2

8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9

15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16

22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23

29 30 27 28 29 30 31 24 25 26 27 28 29 30

 

July August September

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 7 1 2 3 4 1

8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8

15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15

22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22

29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29

30

October November December

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 1 2 3 1

7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8

14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15

21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22

28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29

30 31

 

4、hwclock命令是一个硬件时钟访问工具,它可以显示当前时间、设置硬件时钟的时间和设置硬件时钟为系统时间,也可设置系统时间为硬件时钟的时间。

在Linux中有硬件时钟与系统时钟等两种时钟。

硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟。

系统时钟(软件时钟)则是指kernel中的时钟。当Linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作。所有Linux相关指令与函数都是读取系统时钟的设定。

参数说明:

--adjust:hwclock每次更改硬件时钟时,都会记录在/etc/adjtime文件中。使用--adjust参数,可使hwclock根据先前的记录来估算硬件时钟的偏差,并用来校正目前的硬件时钟;

--debug:显示hwclock执行时详细的信息

--directisa:hwclock预设从/dev/rtc设备来存取硬件时钟。若无法存取时,可用此参数直接以I/O指令来存取硬件时钟

--hctosys:将系统时钟调整为与目前的硬件时钟一致

--systohc:将硬件时钟调整为与目前的系统时钟一致

--set --date=<日期与时间>:设定硬件时钟

--show:显示硬件时钟的时间与日期

--test:仅测试程序,而不会实际更改硬件时钟

--utc:若要使用格林威治时间,请加入此参数,hwclock会执行转换的工作

--version:显示版本信息

 

参考来源:http://man.linuxde.net/hwclock

Linux学习之十-Linux系统时间的更多相关文章

  1. Linux学习之十四、管线命令

    Linux学习之十四.管线命令 地址:http://vbird.dic.ksu.edu.tw/linux_basic/0320bash_6.php

  2. Linux学习之二-Linux系统的目录结构

    Linux学习之二-Linux系统的目录结构 在Linux的根目录下,有很多的目录,但是需要记住,对于Linux而言,一切皆文件.因此此处的目录也是文件.用ls / 命令就能看到根目录下的各类不同的目 ...

  3. Linux学习笔记(七) 查询系统

    1.查看命令 (1)man 可以使用 man 命令名称 命令查看某个命令的详细用法,其显示的内容如下: NAME:命令名称 SYNOPSIS:语法 DESCRIPTION:说明 OPTIONS:选项 ...

  4. Linux学习心得之 Linux下命令行Android开发环境的搭建

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Linux学习心得之 Linux下命令行Android开发环境的搭建 1. 前言2. Jav ...

  5. linux学习书籍推荐linux学习书籍推荐

    引用地址:http://www.cnblogs.com/notepi/archive/2013/06/15/3137103.html Linux 学习书目推荐 Linux基础 1.<Linux与 ...

  6. Linux学习心得之 Linux下ant安装与使用

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Linux学习心得之 Linux下ant安装与使用 1. 前言2. ant安装3. 简单的a ...

  7. linux基础-第十单元 系统的初始化和服务

    第十单元 系统的初始化和服务 Linux系统引导的顺序 Linux系统引导的顺序 BOIS的初始化和引导加载程序 什么是BIOS GRUB程序和grub.conf文件 什么是grub grub配置文件 ...

  8. linux查看和修改当前系统时间

    一.查看和修改Linux的时区 1. 查看当前时区 命令 : "date -R" 2. 修改设置Linux服务器时区 方法 A 命令 : "tzselect" ...

  9. 【转】Windows与Linux(Ubuntu)双系统时间不一致的解决方法

    当在嵌入式Linux里面备份文件时候,在备份的时候,PC(win7)和开发板的时间都是9:30,但是在开发板发现文件创建时间是9:30,然后u盘插在PC(win7)上,发现文件创建时间是1:30,为什 ...

随机推荐

  1. 第二个python自动化练习

    #Author:xiaoxiao from selenium import webdriver import unittest class DownLoad(unittest.TestCase): # ...

  2. Vue2.0 - 生命周期

    <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  3. @inerface的11条规范写法

    总结一些interface声明时的规范,相关宏的介绍,定义方法时有用的修饰符,编写注释的规范,最终写出一个合格的头文件. 1.读写权限 1.1实例变量的@public,@protected,@priv ...

  4. 【bzoj1316】树上的询问 树的点分治+STL-set

    题目描述 一棵n个点的带权有根树,有p个询问,每次询问树中是否存在一条长度为Len的路径,如果是,输出Yes否输出No. 输入 第一行两个整数n, p分别表示点的个数和询问的个数. 接下来n-1行每行 ...

  5. home.php

    home.php <?php error_reporting(0); //抑制所有错误信息 @header("content-Type: text/html; charset=utf- ...

  6. Java注解解析-搭建自己的注解处理器(CLASS注解使用篇)

    该文章是继Java注解解析-基础+运行时注解(RUNTIME)之后,使用注解处理器处理CLASS注解的文章.通过完整的Demo例子介绍整个注解处理器的搭建流程以及注意事项,你将知道如何去搭建自己的注解 ...

  7. 折线统计(line)

    折线统计(line) 题目描述 二维平面上有n个点(xi, yi),现在这些点中取若干点构成一个集合S,对它们按照x坐标排序,顺次连接,将会构成一些连续上升.下降的折线,设其数量为f(S).如下图中, ...

  8. bzoj3694最短路

    bzoj3694最短路 Description 给出一个n个点m条边的无向图,n个点的编号从1~n,定义源点为1.定义最短路树如下:从源点1经过边集T到任意一点i有且仅有一条路径,且这条路径是整个图1 ...

  9. SQL语句效率问题的几点总结

    原文发布时间为:2009-10-29 -- 来源于本人的百度文章 [由搬家工具导入] 1. SQL优化的原则是: 将一次操作需要读取的BLOCK数减到最低,即在最短的时间达到最大的数据吞吐量。   调 ...

  10. soap1.1与soap1.2区别