博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
date -d的灵活应用
阅读量:6488 次
发布时间:2019-06-24

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

* To print the date of the day before yesterday:
比如现在的时间是  date   :    2017年 05月 01日 星期一 02:02:39 CST

          date --date "1 days ago"  ==date -d "1 days ago"
                     结果为:2017年 04月 30日 星期日 02:03:01 CST
   * To print the date of the day three months and one day hence:
          date --date '3 months 1 day' == date -d "3 months 1 day"

       结果为:  2017年 08月 02日 星期三 02:03:49 CST 3个月零一天之后
   * 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

本文转自 zfno11 51CTO博客,原文链接:http://blog.51cto.com/zfno111/1943422

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

你可能感兴趣的文章
linux hosts一个诡异问题
查看>>
Unity3d 嵌入GoogleMap
查看>>
使用IDEA进行远程调试
查看>>
c++ 发布动态.so
查看>>
城市之间的最短总距离(最小生成树算法)
查看>>
使用CSS为图片添加边框的几种方法
查看>>
实现拖动文件到窗体(控件)
查看>>
对 sql server 数据库的备份进行加密
查看>>
YY博客园UML时序图之博客模块
查看>>
《深入浅出 Java Concurrency》—锁紧机构(一)Lock与ReentrantLock
查看>>
Nginx+Keepalived主备切换(包含nginx服务停止)
查看>>
【linux高级程序设计】(第十三章)Linux Socket网络编程基础 4
查看>>
android中画文字的换行 办法(对于遇到canvas.drawText(String s )无法实现换行问题的解决)...
查看>>
Android IOS WebRTC 音视频开发总结(三九)-- win10升级为何要p2p
查看>>
树莓派的rc.local档(设置开机)
查看>>
chrome打开本地文件目录
查看>>
mysql ODBC 在64位下提示找不到odbc驱动问题
查看>>
MySQL的事务处理及隔离级别
查看>>
一个测试SQL2005数据库连接JSP档
查看>>
JspContext对象与PageContext对象
查看>>