date

命令功能

查询及设置系统时间。

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