• shell date 相关使用


    #格式化输出                                                                                
    $> date +"%Y-%m-%d"                                                                        
    2009-12-07                                                                                 
                                                                                               
    #输出昨天日期                                                                              
    $> date -d "1 day ago" +"%Y-%m-%d"                                                         
    2012-11-19                                                                                 
                                                                                               
    #2秒后输出                                                                                 
    $> date -d "2 second" +"%Y-%m-%d %H:%M.%S"                                                 
    2012-11-20 14:21.31                                                                        
                                                                                               
    #传说中的 1234567890 秒                                                                    
    $> date -d "1970-01-01 1234567890 seconds" +"%Y-%m-%d %H:%m:%S"                            
    2009-02-13 23:02:30                                                                        
                                                                                               
    #普通转格式                                                                                
    $> date -d "2009-12-12" +"%Y/%m/%d %H:%M.%S"                                               
    2009/12/12 00:00.00                                                                        
                                                                                               
    #apache格式转换                                                                            
    $> date -d "Dec 5, 2009 12:00:37 AM" +"%Y-%m-%d %H:%M.%S"                                  
    2009-12-05 00:00.37                                                                        
                                                                                               
    #格式转换后时间游走                                                                        
    $>date -d "Dec 5, 2009 12:00:37 AM 2 year ago" +"%Y-%m-%d %H:%M.%S"                        
    2007-12-05 00:00.37                                                                        
                                                                                               
    #加减操作                                                                                  
    date +%Y%m%d                   //显示前天年月日                                            
    date -d "+1 day" +%Y%m%d       //显示前一天的日期                                          
    date -d "-1 day" +%Y%m%d       //显示后一天的日期                                          
    date -d "-1 month" +%Y%m%d     //显示上一月的日期                                          
    date -d "+1 month" +%Y%m%d     //显示下一月的日期                                          
    date -d "-1 year" +%Y%m%d      //显示前一年的日期                                          
    date -d "+1 year" +%Y%m%d      //显示下一年的日期                                          
                                                                                               
                                                                                               
    #设定时间                                                                                  
    date -s                        //设置当前时间,只有root权限才能设置,其他只能查看          
    date -s 20120523               //设置成20120523,这样会把具体时间设置成空00:00:00          
    date -s 01:01:01               //设置具体时间,不会对日期做更改                            
    date -s "01:01:01 2012-05-23"  //这样可以设置全部时间                                      
    date -s "01:01:01 20120523"    //这样可以设置全部时间                                      
    date -s "2012-05-23 01:01:01"  //这样可以设置全部时间                                      
    date -s "20120523 01:01:01"    //这样可以设置全部时间                                      
                                                                                               
    有时需要检查一组命令花费的时间,举例:                                                     
                                                                                               
    #!/bin/bash                                                                                
                                                                                               
    start=$(date +%s)                                                                          
    nmap www.1987.name &> /dev/null                                                            
                                                                                               
    end=$(date +%s)                                                                            
    difference=$(( end - start ))                                                              
    echo $difference seconds.                                                                  

  • 相关阅读:
    输入'过程'求方差算法的简单优化(免去数组的使用)
    PAT 甲级 1002 A+B for Polynomials
    常见算法时间函数的增长趋势分析
    洛谷 P4888 三去矩阵
    PAT 甲级 1001 A+B Format
    网站云服务器迁移时遇到的坑
    Angular JS中自定义标签 属性绑定的解释
    how to do a mass update in Laravel5 ( 在Laravel 5里面怎么做大量数据更新 )
    javascript 到将来某个时间(2020-5-20)的倒计时
    javascript 数字日期格式转换为中文
  • 原文地址:https://www.cnblogs.com/bigbean/p/3657670.html
Copyright © 2020-2023  润新知