Home > Operation and Maintenance > Linux Operation and Maintenance > How to check and modify system time in linux

How to check and modify system time in linux

青灯夜游
Release: 2020-10-13 10:22:49
Original
57101 people have browsed it

How to check the system time in Linux: use the "date" command to display the current system time in the default format; how to modify the system time: use the "date -s time" command, for example "date -s 14: 20:50" command can set the time to 14:20 minutes and 50 seconds.

How to check and modify system time in linux

How to check the current system time?

The date command is used to display the system time. The date can be displayed in the specified format. If you only type date, the current system time will be displayed in the default format. [Video tutorial recommendation: linux tutorial]

Example:

[root@localhost ~]# date
Fri Mar 1 10:36:45 PDT 2019
Copy after login

You can also display the date in a specified format. You can use a string starting with " " to specify its format. The detailed format is as follows:

%n : 下一行
%t : 跳格
%H : 小时(00-23)
%I : 小时(01-12)
%k : 小时(0-23)
%l : 小时(1-12)
%M : 分钟(00-59)
%p : 显示本地 AM 或 PM
%r : 直接显示时间 (12 小时制,格式为 hh:mm:ss [AP]M)
%s : 从 1970 年 1 月 1 日 00:00:00 UTC 到目前为止的秒数
%S : 秒(00-60)
%T : 直接显示时间 (24 小时制)
%X : 相当于 %H:%M:%S
%Z : 显示时区
%a : 星期几 (Sun-Sat)
%A : 星期几 (Sunday-Saturday)
%b : 月份 (Jan-Dec)
%B : 月份 (January-December)
%c : 直接显示日期与时间
%d : 日 (01-31)
%D : 直接显示日期 (mm/dd/yy)
%h : 同 %b
%j : 一年中的第几天 (001-366)
%m : 月份 (01-12)
%U : 一年中的第几周 (00-53) (以 Sunday 为一周的第一天的情形)
%w : 一周中的第几天 (0-6)
%W : 一年中的第几周 (00-53) (以 Monday 为一周的第一天的情形)
%x : 直接显示日期 (mm/dd/yy)
%y : 年份的最后两位数字 (00.99)
%Y : 完整年份 (0000-9999)
Copy after login

Example:

[root@localhost ~]# date +'%Y-%m-%d %H:%M:%S'
2019-03-01 10:38:25
Copy after login

How to modify the system time?

You can use the date command in the following format to modify the system time

date -s  时间
Copy after login

Example:

//将日期设置为2014年6月18日
[root@localhost ~]# date -s 06/18/14

//将时间设置为14点20分50秒
[root@localhost ~]# date -s 14:20:50

//将时间设置为2014年6月18日14点16分30秒(格式:MMDDhhmmYYYY.ss)
[root@localhost ~]# date 0618141614.30
Copy after login

Output:

How to check and modify system time in linux

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to check and modify system time in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template