去评论
海欣资源

Linux系统date命令使用方法

Spring
2022/06/12 00:20:37
涓銆乨ate鍛戒护绠浠
鈥冣僉inux date鍛戒护鍙互鐢ㄦ潵鏄剧ず鎴栬瀹氱郴缁熺殑鏃ユ湡涓庢椂闂淬傚湪鏄剧ず鏂归潰浣跨敤鑰呭彲浠ヨ瀹氭鏄剧ず鐨勬牸寮忥紝鏍煎紡璁惧畾涓轰竴涓姞鍙峰悗鎺ユ暟涓爣璁般傚湪澶囦唤鏂囦欢鐨勬椂鍊欐垜浠父缁撳悎姝ゅ懡浠ょ敓鎴愬綋鍓嶆棩鏈熷拰鏃堕棿鐨勬枃浠跺悕銆傛牸寮忕鍓嶉潰浠+鍔犲彿寮澶达紝鑻ユ槸涓嶄互鍔犲彿浣滀负寮澶达紝鍒欒〃绀鸿璁惧畾鏃堕棿锛岃屾椂闂存牸寮忎负 MMDDhhmm[[CC]YY][.ss]锛屽叾涓 MM 涓烘湀浠斤紝DD 涓烘棩锛宧h 涓哄皬鏃讹紝mm 涓哄垎閽燂紝CC 涓哄勾浠藉墠涓や綅鏁板瓧锛孻Y 涓哄勾浠藉悗涓や綅鏁板瓧锛宻s 涓虹鏁般

浜屻佷娇鐢ㄧず渚
1銆佽幏鍙栧懡浠ゅ府鍔
    [root@s145 ~]# date --help

2銆佹煡鐪嬪懡浠ょ増鏈
    [root@s145 ~]# date --version
    date (GNU coreutils) 8.22
    Copyright 漏 2013 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by David MacKenzie.

3銆佹煡鐪嬬郴缁熸棩鏈熷強鏃堕棿
    [root@s145 ~]# date
    Sat Jan 22 15:08:12 CST 2022

4銆佷互YYYY-MM-DD鏄剧ず鏃ユ湡
    [root@s145 ~]# date +%F
    2022-01-22

5銆佷互MM/DD/YY鏄剧ず鏃ユ湡
    [root@s145 ~]# date +%D
    01/22/22

6銆佷互MM/DD/YYYY鏄剧ず鏃ユ湡
    [root@s145 ~]# date +%x
    01/22/2022

7銆佽幏鍙栫郴缁熷勾浠姐佹湀浠姐佹棩瀛
    [root@s145 ~]# date +%Y
    2022
    [root@s145 ~]# date +%m
    01
    [root@s145 ~]# date +%d
    22

8銆佽幏鍙栫郴缁熸槦鏈熷
    [root@s145 ~]# date +%a
    Sat
    [root@s145 ~]# date +%A
    Saturday
    [root@s145 ~]# date +%u
    6
    [root@s145 ~]# date +%w
    6

9銆佽幏鍙栫郴缁熸椂鍖
    [root@s145 ~]# date +%z
    +0800
    [root@s145 ~]# date +%Z
    CST

10銆佹煡璇㈠綋鍓嶆棩鏈熸槸涓骞翠腑鐨勭鍑犲懆
    [root@s145 ~]# date +%W
    03
    [root@s145 ~]# date +%U
    03

11銆佽幏鍙栫郴缁熸椂闂
    [root@s145 ~]# date +%T
    15:51:42
    [root@s145 ~]# date +%X
    03:53:30 PM

12銆佹樉绀哄崄浜屽皬鏃跺埗鏃堕棿
    [root@s145 ~]# date +%r
    03:51:58 PM

13銆佹樉绀24灏忔椂鍒舵椂闂
    [root@s145 ~]# date +%R
    15:52

14銆佹寜鐓ф寚瀹氭牱寮忔樉绀烘椂闂
    [root@s145 ~]# date +%H-%M.%S
    15-55.07
    [root@s145 ~]# date +%H.%M.%S
    15.55.10

15銆佷粠 1970 骞 1 鏈 1 鏃 00:00:00 UTC 鍒扮洰鍓嶄负姝㈢殑绉掓暟
    [root@s145 ~]# date +%s
    1642838148

16銆佽缃郴缁熸椂闂


17銆佽缃椂闂村強鏃ユ湡



18銆佹寜鐓ф寚瀹氭牸寮忔樉绀烘椂闂村拰鏃ユ湡


19銆佹棩鏈熷拰鏃堕棿鍒嗚鏄剧ず
    [root@s145 ~]# date +%F%n%T
    2022-01-22
    16:36:51

20銆佹寜鐓у瓧绗︿覆鐨勮缃樉绀烘棩鏈



涓夈佷娇鐢ㄨ娉曞強鍙傛暟璇存槑
1銆佷娇鐢ㄨ娉

    鐢ㄦ硶锛#date [鍙傛暟閫夐」] [+鏍煎紡]
    鎴栬咃細date [-u|鈥搖tc|鈥搖niversal] [MMDDhhmm[[CC]YY][.ss]]

2銆佸弬鏁拌鏄



3銆佹椂闂存牸寮忕鍙

4銆佹棩鏈熸牸寮忕鍙