博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux date -d参数用法
阅读量:5764 次
发布时间:2019-06-18

本文共 2881 字,大约阅读时间需要 9 分钟。

最近偶为了写一个调整时间的shell而绞尽脑汁,结果在某一天

#info data
这里面看到了data -d参数的灵活用法,真是欣喜若狂。好东西要保存,整理整理: 
   * To print the date of the day before yesterday:
          date --date='2 days ago' 
   * To print the date of the day three months and one day hence:
          date --date='3 months 1 day'
   * To print the day of year of Christmas in the current year:
          date --date='25 Dec' +%j
   * To print the current full month name and the day of the month:
          date '+%B %d'
     But this may not be what you want because for the first nine days
     of the month, the `%d' expands to a zero-padded two-digit field,
     for example `date -d 1may '+%B %d'' will print `May 01'.
   * To print a date without the leading zero for one-digit days of the
     month, you can use the (GNU extension) `-' flag to suppress the
     padding altogether:
          date -d 1may '+%B %-d
   * To print the current date and time in the format required by many
     non-GNU versions of `date' when setting the system clock:
          date +%m%d%H%M%Y.%S
   * To set the system clock forward by two minutes:
          date --set='+2 minutes'
   * To print the date in RFC 2822 format, use `date --rfc-2822'.  Here
     is some example output:
          Fri, 09 Sep 2005 13:51:39 -0700
   * To convert a date string to the number of seconds since the epoch
     (which is 1970-01-01 00:00:00 UTC), use the `--date' option with
     the `%s' format.  That can be useful in sorting and/or graphing
     and/or comparing data by date.  The following command outputs the
     number of the seconds since the epoch for the time two minutes
     after the epoch:
          date --date='1970-01-01 00:02:00 +0000' +%s
          
          date --date='1970-01-01 00:02:00 +0000' +%s
          120
     If you do not specify time zone information in the date string,
     `date' uses your computer's idea of the time zone when
     interpreting the string.  For example, if your computer's time
     zone is that of Cambridge, Massachusetts, which was then 5 hours
     (i.e., 18,000 seconds) behind UTC:
          # local time zone used
          date --date='1970-01-01 00:02:00' +%s
          18120
   * If you're sorting or graphing dated data, your raw date values may
     be represented as seconds since the epoch.  But few people can
     look at the date `946684800' and casually note "Oh, that's the
     first second of the year 2000 in Greenwich, England."
          date --date='2000-01-01 UTC' +%s
          946684800
     An alternative is to use the `--utc' (`-u') option.  Then you may
     omit `UTC' from the date string.  Although this produces the same
     result for `%s' and many other format sequences, with a time zone
     offset different from zero, it would give a different result for
     zone-dependent formats like `%z'.
          date -u --date=2000-01-01 +%s
          946684800
     To convert such an unwieldy number of seconds back to a more
     readable form, use a command like this:
          # local time zone used
          date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %T %z"
          1999-12-31 19:00:00 -0500
     Often it is better to output UTC-relative date and time:
          date -u -d '1970-01-01 946684800 seconds' +"%Y-%m-%d %T %z"
          2000-01-01 00:00:00 +0000

转载地址:http://rlgkx.baihongyu.com/

你可能感兴趣的文章
深克隆与序列化效率的比较
查看>>
lamp+nginx代理+discuz+wordpress+phpmyadmin搭建一
查看>>
nagios监控使用139邮箱报警
查看>>
Windows Phone 7 中各种Task解说(启动器与选择器)
查看>>
罗森伯格助力2011年中国智能建筑技术发展应用论坛哈尔滨站
查看>>
windows server 2016 活动目录(二)
查看>>
openstack G版 修改vm的flavor级别
查看>>
python_控制台输出带颜色的文字方法
查看>>
java泛型中特殊符号的含义
查看>>
Android组件化最佳实践 ARetrofit原理
查看>>
舍弃浮躁, 50条重要的C++学习建议
查看>>
同步手绘板——将View的内容映射成Bitmap转图片导出
查看>>
【Android游戏开发之十】(优化处理)详细剖析Android Traceview 效率检视工具!分析程序运行速度!并讲解两种创建SDcard方式!...
查看>>
微信小程序之wx.navigateback往回携带参数
查看>>
陌陌和请吃饭之类的应用,你要是能玩转,那就厉害了
查看>>
递归的运行机制简单理解
查看>>
汉字转阿斯克马值
查看>>
Java 栈与堆简介
查看>>
【supervisord】部署单进程服务的利器
查看>>
zabbix oracle监控插件orabbix部署安装
查看>>