Linux哪个命令可以查看当前系统时间?

Linux哪个命令可以查看当前系统时间?,第1张

题主你好,

最常用的命令是: date

上面的的截图是date命令的默认输出,我们还可以根据自己的需要,格式化输出,如我以"年-月-日 时:分:秒"的形式查看:

可以看出,还是自己定义的输出格式看起来比较顺眼.

*.具体的格式化参数都有哪些, 还需要题主自己查看date命令的帮助文档详细的看一下, 但一般情况下上面的这两种情况就够用了

-----

另外,如果只是想看时间,命令应该有很多, 因为有的命令在输出的时候当前时间只是其中的一项,如uptime命令:

=====

希望可以帮到题主, 欢迎追问.

Linux查看系统时间命令:

1、系统硬件时间:

hwclock  -r

2、系统时间

date

硬件时钟可以理解为主板时钟,系统时间会在重启时去同步主板时间

在Linux中有硬件时钟与系统时钟两种时钟。硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟。系统时钟则是指kernel中的时钟。所有Linux相关指令与函数都是读取系统时钟的设定。因为存在两种不同的时钟,那么它们之间就会存在差异。当Linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作。

用date命令对系统时间进行设置后,并不会去修改硬件时钟,所以系统重启后,系统时间还算会去读取硬件时间,这就是为何date设置失效到原因。

因此,需要在设置系统时间后,将系统时间同步到硬件时钟。

clock/hwclock:

显示与设定硬件时钟(query and set the hardware clock (RTC)),两个命令相同。RTC=Real Time Clock,也就是硬件时钟。

命令参数:

-r, --show        读取并打印硬件时钟(read hardware clock and print result)-s, --hctosys     将硬件时钟同步到系统时钟(set the system time from the hardware clock)-w, --systohc     将系统时钟同步到硬件时钟(set the hardware clock to the current system time)

命令示例:

1. 查看硬件时钟

2014年03月27日 星期四 11时03分50秒  -0.328520 seconds

[root@localhost ~]# hwclock -r

2014年03月27日 星期四 11时03分53秒  -0.797264 seconds

[root@localhost ~]# hwclock --show

2014年03月27日 星期四 11时04分01秒  -0.672267 seconds

2. clock与hwclock相同

[root@localhost ~]# type -a hwclock

hwclock is /sbin/hwclock

hwclock is /usr/sbin/hwclock

[root@localhost ~]# ll /sbin/hwclock /usr/sbin/hwclock

-rwxr-xr-x. 1 root root 46940 11月 22 23:27 /sbin/hwclock

lrwxrwxrwx. 1 root root    18 3月  26 19:27 /usr/sbin/hwclock ->../../sbin/hwclock

[root@localhost ~]# type -a clock

clock is /sbin/clock

[root@localhost ~]# ll /sbin/clock

lrwxrwxrwx. 1 root root 7 3月  26 19:27 /sbin/clock ->hwclock

3. 同步系统时间到硬件时钟

[root@localhost ~]# hwclock2014年03月27日 星期四 18时50分51秒  -0.312960 seconds

[root@localhost ~]# date

2014年 03月 27日 星期四 10:50:55 CST

[root@localhost ~]# hwclock -w

[root@localhost ~]# hwclock2014年03月27日 星期四 10时51分15秒  -0.875387 seconds

同步网络时间到系统时间

[root@localhost ~]# ntpdate 210.72.145.4427 Mar 11:11:24 ntpdate[4766]: adjust time server 210.72.145.44 offset 0.011401 sec

210.72.145.44 (中国西安授时中心的官方时间同步服务器IP域名)

同步网络时间到系统时间后,就可以用hwclock -w将系统时间同步到硬件时间。

修改时区

可能部分系统在执行以上两步后,在重启后仍然失效,所以需要进行时区修改。

[root@localhost ~]# tzselect #按照提示进行选择时区

[root@localhost ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

修改系统时间配置文件

[root@localhost ~]# /etc/sysconfig/clock

#打开clock文件,将相关内容改成以下内容

UTC=false

ARC=false

ZONE="Asia/Shanghai"

重启系统

[root@localhost ~]# reboot


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8532492.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-17
下一篇 2023-04-17

发表评论

登录后才能评论

评论列表(0条)

保存