Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > 其他编程语言 > 如何让date轻松显示前一天、前n天的日期
【标  题】:如何让date轻松显示前一天、前n天的日期
【关键字】:date
【来  源】:http://blog.chinaunix.net/article.php?articleId=54652&blogId=11263

如何让date轻松显示前一天、前n天的日期

Your Ad Here

刚刚在网上看到这篇关于如何让date轻松显示前一天、前n天的日期的文章,觉得不错,就收藏先了。

 
原文:http://www.labri.fr/Perso/~strandh/Teaching/USI/Common/Sh-utils/sh-utils_65.html
作者:David MacKenzie et al.

Examples of date

Here are a few examples. Also see the documentation for the `-d' option in the previous section.

  • 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) - modifier 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 the format specified by RFC-822, use `date --rfc'. I just did and saw this:
    Mon, 25 Mar 1996 23:34:17 -0600
    
  • 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 one second later than the epoch, but in time zone five hours later (Cambridge, Massachusetts), thus a total of five hours and one second after the epoch:
    date --date='1970-01-01 00:00:01 UTC +5 hours' +%s
    18001
    
    Suppose you had not specified time zone information in the example above. Then, date would have used your computer's idea of the time zone when interpreting the string. Here's what you would get if you were in Greenwich, England:
    # local time zone used
    date --date='1970-01-01 00:00:01' +%s
    1
    
  • 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."
    date --date='2000-01-01 UTC' +%s
    946684800
    
    To convert such an unwieldy number of seconds back to a more readable form, use a command like this:
    date -d '1970-01-01 946684800 sec' +"%Y-%m-%d %T %z"
    2000-01-01 00:00:00 +0000
crontab命令的功能:【上一篇】
关于jsp网页弹出窗口:【下一篇】
【相关文章】
  • RH9 UPDATE 2.6 KERNEL + IPTALBES
  • GCC 4.0 Release candidate 1 Available
  • Red Hat Enterprise Linux AS 3 Update 5 Release
  • [DOWNLOAD] Red Hat Enterprise Linux AS 3 Update 5
  • Problem in installing MySQL on RHEL AS3 Update3
  • 用grub引导,从硬盘安装Centos4.2(RedHat Enterprise Linux 4 Update2)
  • 瞬间搞定百台Windows升级(update)
  • Windows 2000的Update服务将终止
  • rpm update - ioctl: LOOP_SET_FD: Invalid argument
  • SHELL DATE命令 详解
  • 【随机文章】
  • 实战MPLS VPN
  • 亚健康的典型症状
  • 诊断DB2数据库锁的问题
  • Mediawiki安装纪要
  • 为什么程序员不应调用“sun”包
  • 中国红客联盟今又重组
  • AGATE200高速接入网桥/路由器
  • Hibernate 3 Formulas
  • xoWidgets 编程风格
  • Recommand of the Day: 两个有趣的网站
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.