Skynet

          ---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks

          date demo:
          實(shí)例:
          $
          >date
          Mon Dec  
          7 15:43:39 CST 2009

          #格式化輸出
          $> date +"%Y-%m-%d"
          2009-12-07

          #時(shí)間游走 當(dāng)前時(shí)間 2009-12-07
          # year , month , day ,hour , minute,second  - ago
          #昨天輸出

          $> date  -"1 day ago" +"%Y-%m-%d"
          2009-12-06

          #2秒后輸出
          $> date  -"2 second" +"%Y-%m-%d %H:%M.%S"
          2009-12-07 15:50.04

          #傳說(shuō)中的 1234567890 秒
          $>date -"1970-01-01  1234567890 seconds"  +"%Y-%m-%d %H:%m:%S"
          2009-02-13 23:02:30

          #其他格式的轉(zhuǎn)換
          date -"$(echo "03/Nov/2009 11:04:28" |perl -ne 'print "$2 $1 $3 $4\n" if /(.*?)"/(.*?)"/(.*?) (.*)/;') " +%Y-%m-%d
          2009-11-03

          #普通 轉(zhuǎn)格式
          $> date -"2009-12-12" +"%Y/%m/%d %H:%M.%S"
          2009/12/12 00:00.00

          #apache 格式轉(zhuǎn)換
          $>date  -"Dec 5, 2009 12:00:37 AM" +"%Y-%m-%d %H:%M.%S"
          2009-12-05 00:00.37

          #格式轉(zhuǎn)換 后時(shí)間 游走
          $>date  -"Dec 5, 2009 12:00:37 AM 2 year ago" +"%Y-%m-%d %H:%M.%S"
          2007-12-05 00:00.37


          #時(shí)間差
          #一小時(shí) 3600
          #一天 86400 秒

          $>st=$(date  -"Dec 5, 2009 12:00:37 AM 1 day ago 1 hour ago " +"%s")
          $
          >et=$(date  -"Dec 5, 2009 12:00:37 AM" +"%s")
          $
          >echo "時(shí)間差$[($et-$st)/86400]天,$[($et-$st)/3600%24]小時(shí)"
          時(shí)間差1天,1小時(shí)





          date --help
          Usage: date [OPTION] [+FORMAT]
            or
          :  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
          Display the current 
          time in the given FORMAT, or set the system date.

            
          -d, --date=STRING         display time described by STRING, not `now'
            -f, --file=DATEFILE       like --date once for each line of DATEFILE
            -r, --reference=FILE      display the last modification time of FILE
            -R, --rfc-2822            output date and time in RFC 2822 format
                --rfc-3339=TIMESPEC   output date and time in RFC 3339 format.
                                      TIMESPEC=`date
          ', `seconds', or `ns' for
                                      date and 
          time to the indicated precision.
            
          -s, --set=STRING          set time described by STRING
            
          -u, --utc, --universal    print or set Coordinated Universal Time
                
          --help     display this help and exit
                
          --version  output version information and exit
















          整理 www.aygfsteel.com/Good-Game
          posted on 2009-12-07 16:14 劉凱毅 閱讀(2441) 評(píng)論(0)  編輯  收藏 所屬分類: shell
          主站蜘蛛池模板: 泰兴市| 海丰县| 永春县| 金沙县| 县级市| 健康| 博爱县| 南宁市| 木里| 剑阁县| 云阳县| 即墨市| 苍山县| 左权县| 昌吉市| 九江县| 杭锦后旗| 梓潼县| 大丰市| 米泉市| 兰溪市| 朝阳区| 静安区| 贵定县| 霍林郭勒市| 平山县| 依兰县| 壤塘县| 晴隆县| 新闻| 迁安市| 淳安县| 齐齐哈尔市| 资阳市| 清水县| 福贡县| 楚雄市| 衡阳市| 洪江市| 宜都市| 莆田市|