前言

  • linux

date 命令

date命令可以用来显示或设定系统的日期与时间。

常用日期格式定义

> date +"%Y-%m-%d"
2019-09-20
> date +"%Y-%m-%d %H:%M:%S"
2019-09-20 15:59:14
> date -d "1970-01-01 1234567890 seconds" +"%Y-%m-%d %H:%m:%s"
2009-02-13 23:02:1234539090
> date +"%Y%m%d%H%M%S"
20190920155945

参数解释

-d <字符串>:显示字符串所指的日期与时间。字符串前后必须加上双引号;
-s <字符串>:根据字符串来设置日期与时间。字符串前后必须加上双引号;
-u:显示GMT;
–help:在线帮助;
–version:显示版本信息。

日期格式符号含义

%H 小时(以00-23来表示)。
%I 小时(以01-12来表示)。
%K 小时(以0-23来表示)。
%l 小时(以0-12来表示)。
%M 分钟(以00-59来表示)。
%P AM或PM。
%r 时间(含时分秒,小时以12小时AM/PM来表示)。
%s 总秒数。起算时间为1970-01-01 00:00:00 UTC。
%S 秒(以本地的惯用法来表示)。
%T 时间(含时分秒,小时以24小时制来表示)。
%X 时间(以本地的惯用法来表示)。
%Z 市区。
%a 星期的缩写。
%A 星期的完整名称。
%b 月份英文名的缩写。
%B 月份的完整英文名称。
%c 日期与时间。只输入date指令也会显示同样的结果。
%d 日期(以01-31来表示)。
%D 日期(含年月日)。
%j 该年中的第几天。
%m 月份(以01-12来表示)。
%U 该年中的周数。
%w 该周的天数,0代表周日,1代表周一,异词类推。
%x 日期(以本地的惯用法来表示)。
%y 年份(以00-99来表示)。
%Y 年份(以四位数来表示)。
%n 在显示时,插入新的一行。
%t 在显示时,插入tab。

帮助信息

Usage: date [OPTION]... [+FORMAT]or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.Mandatory arguments to long options are mandatory for short options too.-d, --date=STRING         display time described by STRING, not 'now'-f, --file=DATEFILE       like --date once for each line of DATEFILE-I[TIMESPEC], --iso-8601[=TIMESPEC]  output date/time in ISO 8601 format.TIMESPEC='date' for date only (the default),'hours', 'minutes', 'seconds', or 'ns' for dateand time to the indicated precision.-r, --reference=FILE      display the last modification time of FILE-R, --rfc-2822            output date and time in RFC 2822 format.Example: Mon, 07 Aug 2006 12:34:56 -0600--rfc-3339=TIMESPEC   output date and time in RFC 3339 format.TIMESPEC='date', 'seconds', or 'ns' fordate and time to the indicated precision.Date and time components are separated bya single space: 2006-08-07 12:34:56-06:00-s, --set=STRING          set time described by STRING-u, --utc, --universal    print or set Coordinated Universal Time (UTC)--help     display this help and exit--version  output version information and exitFORMAT controls the output.  Interpreted sequences are:%%   a literal %%a   locale's abbreviated weekday name (e.g., Sun)%A   locale's full weekday name (e.g., Sunday)%b   locale's abbreviated month name (e.g., Jan)%B   locale's full month name (e.g., January)%c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)%C   century; like %Y, except omit last two digits (e.g., 20)%d   day of month (e.g., 01)%D   date; same as %m/%d/%y%e   day of month, space padded; same as %_d%F   full date; same as %Y-%m-%d%g   last two digits of year of ISO week number (see %G)%G   year of ISO week number (see %V); normally useful only with %V%h   same as %b%H   hour (00..23)%I   hour (01..12)%j   day of year (001..366)%k   hour, space padded ( 0..23); same as %_H%l   hour, space padded ( 1..12); same as %_I%m   month (01..12)%M   minute (00..59)%n   a newline%N   nanoseconds (000000000..999999999)%p   locale's equivalent of either AM or PM; blank if not known%P   like %p, but lower case%r   locale's 12-hour clock time (e.g., 11:11:04 PM)%R   24-hour hour and minute; same as %H:%M%s   seconds since 1970-01-01 00:00:00 UTC%S   second (00..60)%t   a tab%T   time; same as %H:%M:%S%u   day of week (1..7); 1 is Monday%U   week number of year, with Sunday as first day of week (00..53)%V   ISO week number, with Monday as first day of week (01..53)%w   day of week (0..6); 0 is Sunday%W   week number of year, with Monday as first day of week (00..53)%x   locale's date representation (e.g., 12/31/99)%X   locale's time representation (e.g., 23:13:48)%y   last two digits of year (00..99)%Y   year%z   +hhmm numeric time zone (e.g., -0400)%:z  +hh:mm numeric time zone (e.g., -04:00)%::z  +hh:mm:ss numeric time zone (e.g., -04:00:00)%:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)%Z   alphabetic time zone abbreviation (e.g., EDT)By default, date pads numeric fields with zeroes.
The following optional flags may follow '%':-  (hyphen) do not pad the field_  (underscore) pad with spaces0  (zero) pad with zeros^  use upper case if possible#  use opposite case if possibleAfter any flags comes an optional field width, as a decimal number;
then an optional modifier, which is either
E to use the locale's alternate representations if available, or
O to use the locale's alternate numeric symbols if available.Examples:
Convert seconds since the epoch (1970-01-01 UTC) to a date$ date --date='@2147483647'Show the time on the west coast of the US (use tzselect(1) to find TZ)$ TZ='America/Los_Angeles' dateShow the local time for 9AM next Friday on the west coast of the US$ date --date='TZ="America/Los_Angeles" 09:00 next Fri'GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'date invocation'

linux:date 命令相关推荐

  1. linux+date+命令+作业,Linux date命令的使用

    1.命令简介 date命令用于按照指定格式显示当前时间或者指定的时间,也可以设置系统时间.很多Shell脚本里面需要打印不同格式的时间或日期,以及要根据时间和日期执行操作,此时可以使用date命令来完 ...

  2. linux date 小写h,linux date 命令详解[转载]

    linux date 命令详解 使用方式 : date [-u] [-d datestr] [-s datestr] [--utc] [--universal] [--date=datestr] [- ...

  3. linux date命令设置时间

    linux date命令设置时间 其实很简单 # date -s 20060925 # date -s 21:19:50 第一行设置日期,第二行设置时间. 转载于:https://www.cnblog ...

  4. linux date命令_Linux date命令示例

    linux date命令 Unix/Linux date command is a command used for displaying the system's date and time. In ...

  5. [Linux] date命令

    Linux date命令 可用标记如下 时间 %H : 小时(00..23) %I : 小时(01..12) %k : 小时(0..23) %l : 小时(1..12) %M : 分钟(00..59) ...

  6. Linux date命令精确到毫秒

    Linux date命令精确到秒 date +%Y-%m-%d' '%H-%M-%S [root@harbor ~]# date +%Y-%m-%d' '%H-%M-%S 2021-01-25 17- ...

  7. 【Linux】一步一步学Linux——date命令(81)

    00. 目录 文章目录 00. 目录 01. 命令概述 02. 命令格式 03. 常用选项 04. 参考示例 05. 扩展 06. 附录 01. 命令概述 date - 打印或设置系统日期和时间 若是 ...

  8. linux+date+命令+作业,Linux date命令

    date命令是Linux中常用的一个命令,主要作用就是显示本机当前时间.如下: 在本人Linux操作系统中,date命令默认实现格式为年月日-星期-时分秒,然后是CST中央标准时间.不过,你也可以自行 ...

  9. Linux.date命令详解

    格式化 date命令的帮助信息 [root@localhost source]# date --help 用法:date [选项]... [+格式] 或:date [-u|--utc|--univer ...

  10. linux date命令的格式

    我们在linux中使用shell时,想查看日期或时间的时候可以使用date这个命令. date命令的格式: date [option] [+Format] 以下选出几个日常比较常用的时间格式: dat ...

最新文章

  1. java替换特殊字符串
  2. NYOJ 625 笨蛋的难题(二)
  3. 使用SG_IO发送SCSI 指令测试底层驱动的scatter-gather 功能
  4. java udp 缓冲区_为什么特定的UDP消息总是低于特定的缓冲区大小?
  5. Android之You need to use a Theme.AppCompat theme (or descendant) with this activity.
  6. 1058 选择题 (20 分)
  7. [机器学习笔记]Note15--大规模机器学习
  8. 语音识别学习日志 2019-7-13 语音识别基础知识准备 1{语音基础知识}
  9. 【Git】PyCharm项目关联Git的解决方案
  10. mysql安装及远程连接_Mysql安装、使用、配置远程连接,看这一篇就够了!
  11. CSDN 发布开源代码托管平台 GitCode
  12. python---之super()继承,解决钻石继承难题
  13. 寻找二叉树最小叶子节点值
  14. python安卓库拍照_Python Faker库的实战,用Faker库生成伪造的安卓通讯录
  15. 我对于测试团队建设的意见
  16. 全国计算机照片怎么弄,证件照电子版怎么弄-制作证件照其实很简单,用excel就行,2分钟搞定...
  17. 新版曝光骗子公示PHP系统源码+云黑系统
  18. 以太坊Solidity之Truffle的使用流程与集成指南
  19. Paddle-NEAT——飞桨进化神经网络组件
  20. 数字孪生技术在智慧城市规划中的发展影响及其应用

热门文章

  1. 开启物联网的真正潜力需要在更大程度上克服数据挑战
  2. valgrind-3.11.0 交叉编译
  3. How Many Replication Method In SAP HANA
  4. 关于海量数据的SQL查询优化.........
  5. Druid 常见问题
  6. jquery获取一个table中的一行的每个td的内容
  7. js只能输入数字[价格等]
  8. MySQL时间戳(毫秒/秒)与日期格式的相互转换
  9. Go实战--golang中使用redis(redigo和go-redis/redis这个已测试)
  10. PHP算法使用__call优化代码