* 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

date -d的灵活应用相关推荐

  1. java calendar与date_java---Calendar与Date

    1,Calendar Calendar 比Date更加的灵活,但是复杂度也高了 (1):建议Date能完成工作,就不建议使用Calendar. Calendar 是一个抽象类,不能实例化 Calend ...

  2. 使用Schedule来实现动态的定时任务

    使用的是springboot+Schedule来实现定时任务 先在pom.xml中导入依赖 <dependency><groupId>org.quartz-scheduler& ...

  3. BeanUtils介绍及其使用

    BeanUtils工具由Apache软件基金组织编写,提供给我们使用,主要解决的问题是:把对象的属性数据封装到对象中.在整个J2EE的编程过程中,我们经常会从各种配置文件中读取相应的数据,需要明白的一 ...

  4. java 日期 年数_关于java:为什么不赞成使用“新日期(整数年,整数月,整数日)”?...

    我最近继承的应用程序关于构造函数的弃用警告已满: Date d = new Date(int year, int month, int day) 有谁知道或可以指出为什么将类似以下内容的简单内容替换为 ...

  5. Oracle数据库配置完全实战手册

    To be DBA or not to be, that is NOT the question. ---- Arron Oracle8以8.1.5为界分为普通版本和internet版本.普通版版本号 ...

  6. Yahoo 前端雅虎军规

    来这是个老生常谈的问题,上周自成又分享了一些性能优化的建议,我这里再做一个全面的Tips整理,谨作为查阅型的文档,不妥之处,还请指正: 如果你已经对yahoo这些优化建议烂熟于心,果断点这里 一. Y ...

  7. yahoo军规的思考

    针对优化性能,提高网站加载速度,雅虎给出了一系列方案,网上也流传很多个版本,但是基本大同小异 1.减少HTTP请求 合并图片(如css sprites,内置图片使用数据).合并CSS.JS,原理比较简 ...

  8. Spark 2.4重磅发布:优化深度学习框架集成,提供更灵活的流式接收器

    Apache Spark 2.4.0是2.x系列中的第五个版本.此版本增加了屏障执行模式,以便更好地与深度学习框架集成:引入30多个更高阶的内置函数,能够更轻松地处理复杂数据类型:优化K8s集成,同时 ...

  9. (第7篇)灵活易用易维护的hadoop数据仓库工具——Hive

    摘要: Hive灵活易用且易于维护,十分适合数据仓库的统计分析,什么样的结构让它具备这些特性?我们如何才能灵活操作hive呢? 博主福利 给大家推荐一套hadoop视频课程 [百度hadoop核心架构 ...

最新文章

  1. Ant Design of React从入门到开发教程
  2. 干货!整理了50个 Pandas 高频使用技巧,强烈建议收藏!
  3. HDU1011 Starship Troopers(树形dp)
  4. baseline来啦!第三届厦门国际银行数创金融杯金融营销建模大赛(奖金34万!)
  5. 写一个 JavaScript 框架:比 setTimeout 更棒的定时执行
  6. OSI、TCP/IP or Five-layer(Protocols Use) Model
  7. nginx日志格式、参数及切分
  8. Django操作原生MySQL的方法:MyModel.objects.raw()执行查询语句
  9. 【B站免费教程】2W 收藏!火爆 B 站的计算机科学速成教程发布,全中文版
  10. hibernate教程笔记3
  11. 大学的最后一年有一门课程叫“人生”。
  12. php api接口安全设计 sign
  13. 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--蜂鸣器封装(十七)
  14. 微信小程序实现五星评分效果
  15. 批量提取word doc文档中的表格
  16. 亚马逊图片优化五点技巧
  17. Redis的奇葩问题
  18. 中文字符乱码:UTF8、GB2312
  19. 游戏 | python打包游戏为exe可执行文件
  20. stdlib.h和stdio.h有什么区别

热门文章

  1. android 设置PopupWindow的显示大小
  2. CSS3 2D和3D转换 Transform
  3. JS引擎线程的执行过程的三个阶段
  4. SpringSecurity的简单使用使用案列说明
  5. spring中AOP动态代理的两种方式
  6. windows下安装配置mongodb
  7. SDNU 1481.纪念品分组(水题)
  8. 修改 MySQL 自增ID的起始值
  9. Django-Json 数据返回
  10. read write spinlock