mac date 命令使用

环境:系统 macOS Catalina 10.15.7

macOS 的 date 命令使用和 Linux 使用有稍许不同。
放上几个小例子做记录。

macOS 增减日期命令。

usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]date -v -8H '+%Y-%m-%d %H:%M:%S' # ✔️
# 2021-01-29 10:20:23
date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s" # ✔️
# 1611915623
date -j -f "%a %b %d %T %Z %Y" "Fri Jan 29 18:14:18 CST 2021" "+%Y-%m-%d %H:%M:%S" # ✔️
# 2021-01-29 18:14:18
date -v -8H -j -f "%Y-%m-%d %T" "2021-01-29 17:43:00" "+%Y-%m-%d %H:%M:%S" # ✔️
# 输出 2021-01-29 09:43:00============================================================================================================-j:使用-j才能使用-f-n:默认情况下,如果定时进程正在运行,date命令会在本地组的所有机器设置时间。-n可以禁止这种行为,表示只设置当前计算机。-u:显示或者设置日期为UTC(世界协调时钟)时间-d:设置内核的时区,一般不使用-r:秒转换时间-t:(time zone)时区设置(GMT时区)-v:根据参数调整时间不使用+|-,更改对应的时间使用+:增加对应的时间使用-:减少对应的时间-f:根据格式调整时间+:+号引导的一些格式,和正常的Linux格式一致
============================================================================================================-d dst  Set the kernel's value for daylight saving time.  If dst is non-zero, future calls to gettimeofday(2) will return a non-zero for tz_dsttime.-f      Use input_fmt as the format string to parse the new_date provided rather than using the default [[[mm]dd]HH]MM[[cc]yy][.ss] format.  Parsing is done using strptime(3).-j      Do not try to set the date.  This allows you to use the -f flag in addition to the + option to convert one date format to another.-n      By default, if the timed(8) daemon is running, date sets the time on all of the machines in the local group.  The -n option suppresses this behavior and causes the time to be set only on the currentmachine.-R      Use RFC 2822 date and time output format. This is equivalent to use ``%a, %d %b %Y %T %z'' as output_fmt while LC_TIME is set to the ``C'' locale .-r secondsPrint the date and time represented by seconds, where seconds is the number of seconds since the Epoch (00:00:00 UTC, January 1, 1970; see time(3)), and can be specified in decimal, octal, or hex.-r filenamePrint the date and time of the last modification of filename.-t minutes_westSet the system's value for minutes west of GMT.  minutes_west specifies the number of minutes returned in tz_minuteswest by future calls to gettimeofday(2).-u      Display or set the date in UTC (Coordinated Universal) time.-v      Adjust (i.e., take the current date and display the result of the adjustment; not actually set the date) the second, minute, hour, month day, week day, month or year according to val.  If val is pre-ceded with a plus or minus sign, the date is adjusted forwards or backwards according to the remaining string, otherwise the relevant part of the date is set.  The date can be adjusted as many timesas required using these flags.  Flags are processed in the order given.When setting values (rather than adjusting them), seconds are in the range 0-59, minutes are in the range 0-59, hours are in the range 0-23, month days are in the range 1-31, week days are in therange 0-6 (Sun-Sat), months are in the range 1-12 (Jan-Dec) and years are in the range 80-38 or 1980-2038.If val is numeric, one of either y, m, w, d, H, M or S must be used to specify which part of the date is to be adjusted.The week day or month may be specified using a name rather than a number.  If a name is used with the plus (or minus) sign, the date will be put forwards (or backwards) to the next (previous) datethat matches the given week day or month.  This will not adjust the date, if the given week day or month is the same as the current one.When a date is adjusted to a specific value or in units greater than hours, daylight savings time considerations are ignored.  Adjustments in units of hours or less honor daylight saving time.  So,assuming the current date is March 26, 0:30 and that the DST adjustment means that the clock goes forward at 01:00 to 02:00, using -v +1H will adjust the date to March 26, 2:30.  Likewise, if thedate is October 29, 0:30 and the DST adjustment means that the clock goes back at 02:00 to 01:00, using -v +3H will be necessary to reach October 29, 2:30.When the date is adjusted to a specific value that does not actually exist (for example March 26, 1:30 BST 2000 in the Europe/London timezone), the date will be silently adjusted forwards in units ofone hour until it reaches a valid time.  When the date is adjusted to a specific value that occurs twice (for example October 29, 1:30 2000), the resulting timezone will be set so that the datematches the earlier of the two times.It is not possible to adjust a date to an invalid absolute day, so using the switches -v 31d -v 12m will simply fail five months of the year.  It is therefore usual to set the month before settingthe day; using -v 12m -v 31d always works.Adjusting the date by months is inherently ambiguous because a month is a unit of variable length depending on the current date.  This kind of date adjustment is applied in the most intuitive way.First of all, date tries to preserve the day of the month.  If it is impossible because the target month is shorter than the present one, the last day of the target month will be the result.  Forexample, using -v +1m on May 31 will adjust the date to June 30, while using the same option on January 30 will result in the date adjusted to the last day of February.  This approach is alsobelieved to make the most sense for shell scripting.  Nevertheless, be aware that going forth and back by the same number of months may take you to a different date.Refer to the examples below for further details.
============================================================================================================

Linux 增减日期命令。

date -d "-1 hours 2021-01-28 17:43:00" "+%Y-%m-%d %H:%M:%S"
FORMAT 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 possible

macOS date 命令增减时间。相关推荐

  1. linux date命令设置时间

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

  2. linux中date命令PDT,linux系统下date命令修改时间及hwclock硬件时间

    修改日期: 时间设定成2016年5月18日的命令如下: date -s 05/18/2016 修改时间: 将系统时间设定成上午10点10分40秒的命令如下. date -s 10:10:40 修改时区 ...

  3. 【date】Linux date命令修改时间重启后失效的问题

    date命令修改时间重启后失效的问题 问题 原因 解决 总结 问题 使用date命令修改时间成功,但是重启后失效 date命令 => date MMDDhhmmYYYY.ss set 原因    ...

  4. linux设置时间hwclock,linux系统date命令修改时间及hwclock硬件时间

    修改日期: 时间设定成2016年5月18日的命令如下: #date -s 05/18/2016 修改时间: 将系统时间设定成上午10点10分40秒的命令如下. #date -s 10:10:40 修改 ...

  5. linux当前时间 按格式化,Linux下date命令,格式化输出,时间设置

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

  6. linux使用date命令修改系统日期,使用date命令设置CentOS Linux修改系统日期和时间...

    您可以使用date命令来修改CentOS Linux的时间 修改日期: 将时间设置为2014年6月20日的命令如下: #date -s 2014年6月20日 修改时间: 将系统时间设置为14:20:0 ...

  7. 查看日期命令linux,linux date命令查看和设置时间详解(图文)

    date命令 date命令的功能是显示和设置系统日期和时间. 该命令的一般格式为: date [选项] 显示时间格式(以+开头,后面接格式) date 设置时间格式 命令中各选项的含义分别为: 复制代 ...

  8. linux中date命令详解,Linux使用date命令修改日期时间详解linux操作系统 -电脑资料...

    在linux中我们只要使用ROOT管理员进入然后就可以直接使用date函数来修改服务器的日期时间了,如date -s 2013-08-03就设置成功了,下面我来来看看date用法 Linux 时间修改 ...

  9. 使用命令修改linux的时间,Linux使用date命令修改日期时间详解

    Linux 时间修改 不重启修改时区 一.修改linux的时间 root使用date指令:date -s 1.只修改日期,不修改时间,输入: Linux代码 date -s 2007-08-03 2. ...

最新文章

  1. WinDbg 调试命令记录二 (基础CLR查看)
  2. HDU1407 测试你是否和LTC水平一样高 暴力、二分、hash
  3. 小知识系列:数据库的主键和外键
  4. activiti 如何获取下一步节点
  5. Thymeleaf基本知识
  6. c++ 实现ping
  7. 子程序与中断程序的异同_西门子200samrt高速计数器指令向导及程序
  8. 微软版UnityVs横空出世,究竟是谁成就了谁?
  9. (黑马教程)-webpack学习笔记
  10. HP 6L WIN7 WIN8 驱动
  11. html3D创意相册附源码
  12. python-机器学习的两种传统算法-knn,k-means
  13. Java替换第一个和最后一个字符串
  14. oracle安装先决条件检查全部失败,两种解决办法
  15. 神奇的BUG——MATLAB之1
  16. Java多线程篇--线程的等待通知
  17. 解决No such file or directory: /turtlebot3/turtlebot3_description/urdf/turtlebot3_.urdf.xacro
  18. 质数(素数)判断代码实现
  19. 【JAVA 文件概述】
  20. mysql的一些介绍

热门文章

  1. U拼拼团项目靠谱嘛?
  2. 亚马逊签约第五届进博会;黑芝麻智能与MAXIEYE达成合作;新思科技与达索系统合作打造业界首个整体照明设计平台 | 全球TMT...
  3. Vim复制(剪切)粘贴操作
  4. vue插槽样式_Vue 插槽详解
  5. java计算机毕业设计血库系统源码+系统+数据库+lw文档
  6. 【通信原理】确知信号的性质分析与研究
  7. HBase最新面试题总结
  8. vue ElementUI引入第三方icon
  9. Android 10实现全局静音
  10. 查看 KeyStore 文件详细信息命令