date
命令功能
查询及设置系统时间。
命令格式
date
date --help
date +Format
date -s YY/MM/DD
date -s hh:mm:ss
date -r Filename(暂不支持)
参数说明
参数 | 参数说明 | 取值范围 |
---|---|---|
—help | 使用帮助 | |
+Format | 根据Format格式打印时间 | —help中列出的占位符 |
-s YY/MM/DD | 设置系统时间,用“/”分割的年月日 | >= 1970/01/01 |
-s hh:mm:ss | 设置系统时间,用“:”分割的时分秒 | |
-r | 查询文件修改时间(暂不支持) |
使用指南
- date参数缺省时,默认显示当前系统时间。
- --help、+Format、-s、-r不能混合使用。
使用示例
Huawei LiteOS # date
Fri Jan 2 07:05:54 1970
Huawei LiteOS # date --help
Usage: date [+FORMAT]
or: date [-s] [YY/MM/DD] [hh:mm:ss]
Display the current time in the given FORMAT, or set the system date.
FORMAT controls the output. Interpreted sequences are:
%b The abbreviated month name according to the current locale.
%B The full month name according to the current locale.
%C The century number (year/100) as a 2-digit integer. (SU)
%d The day of the month as a decimal number (range 01 to 31).
%e Like %d, the day of the month as a decimal number,
but a leading zero is replaced by a space.
%h Equivalent to %b. (SU)
%H The hour as a decimal number using a 24-hour clock (range 00 to 23).
%I The hour as a decimal number using a 12-hour clock (range 01 to 12).
%j The day of the year as a decimal number (range 001 to 366).
%k The hour (24-hour clock) as a decimal number (range 0 to 23);
single digits are preceded by a blank. (See also %H.) (TZ)
%l The hour (12-hour clock) as a decimal number (range 1 to 12);
single digits are preceded by a blank. (See also %I.) (TZ)
%m The month as a decimal number (range 01 to 12).
%M The minute as a decimal number (range 00 to 59).
%n A newline character. (SU)
%p Either "AM" or "PM" according to the given time value,
or the corresponding strings for the current locale.
Noon is treated as "PM" and midnight as "AM".
%P Like %p but in lowercase: "am" or "pm"
or a corresponding string for the current locale. (GNU)
%s The number of seconds since the Epoch, that is,
since 1970-01-01 00:00:00 UTC. (TZ)
%S The second as a decimal number (range 00 to 60).
(The range is up to 60 to allow for occasional leap seconds.)
%t A tab character. (SU)
%y The year as a decimal number without a century (range 00 to 99).
%Y The year as a decimal number including the century.
%% A literal '%' character.
Examples:
Set system date (2017-01-01)
$ date -s 2017/01/01
Set system time (12:00:00)
$ date -s 12:00:00
Show the time with format Year-Month-Day
$ date +%Y-%m-%d