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. 更改 Mac 上的功能键行为

    您可以将 Apple 键盘上的顶行按键用作标准功能键,或用来控制 Mac 的内建功能.   如果您的 Apple 键盘部分顶行按键上印有图标,则这些按键可用于执行每个图标所示的特殊功能.这些按键也可用 ...

  2. MySQL主从复制入门

    1.MySQL主从复制入门 首先,我们看一个图: MySQL 主从复制与读写分离概念及架构分析 影响MySQL-A数据库的操作,在数据库执行后,都会写入本地的日志系统A中. 假设,实时的将变化了的日志 ...

  3. 【Luogu】P4159迷路(矩阵优化)

    题目链接 将每个点拆成时刻1~9,然后根据题目要求连边,比如i-j有一条权为x的边就从点i-x向点j-1连一条边,表示经过x次之后可以到达. 然后就矩阵快速幂乱搞就好了. #include<cs ...

  4. centos7 mariadb mysql max_connections=214 无法修改的问题

    centos7 mariadb mysql max_connections=214 无法修改的问题 /etc/my.cnf.d/mariadb-server.cnf [mysqld] max_conn ...

  5. 分布式文件系统之Glusterfs

    1.环境规划如下 centos7.4   三个节点一块 sdb  3G大小的测试硬盘 2.Glusterfs  卷的类型比较多,这里我们测试最常用的一种   Distributed Replicate ...

  6. [寒假集训第一场]gym101606 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)

    3星场 难度在于英文题面太难读懂了QAQ 看样例猜题意的我 博客园的c++主题真丑 A Alien Sunset \(description\) 有\(n\)个星球,每个星球自转时间不一样,所以一天的 ...

  7. mongodb使用1

    首先官网下载mongodb放在根目录下.新建db文件夹,在命令行中进入bin路径,然后运行mongod开启命令,同时用--dbpath指定数据存放地点为“db”文件夹 mongod --dbpath= ...

  8. HTML 改变文字方向

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. 控制cxGrid 主从表的明细只展开一个

    procedure TForm.ADetailDataControllerCollapsing( ADataController: TcxCustomDataController; ARecordIn ...

  10. The type or namespace name 'Html' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?)

    The type or namespace name 'Html' does not exist in the namespace 'System.Web.Mvc' (are you missing ...