• 2009-01-18

    Linux的时间 - [Linux学习]

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://wanping.blogbus.com/logs/34040762.html

    linux环境下:

    显示正常时间

    date -d "-1 day" "+%Y%m%d"         //前一天的年月日,返回:20090117

    date -d "1 day" "+%Y%m%d"         //后一天的年月日,返回:20090119

     date +[%Y-%m-%d]                     //当前的年月日,返回:[2009-01-18]
    date +[%H:%M:%S]                       //当前的时间,返回:[04:16:46]
    date -d "-1 hour" "+%H"                 //前一小时的时间

    date -d "1 hour" "+%H"                 //后一小时的时间

    显示时间戳:

    date -d "-1 day" +%s         //前一天的时间戳

     

    date -d "1 day" +%s         //后一天的时间戳

    date -d "-1 hour" +%s               //前一小时的时间戳

    date -d "1 hour" +%s                //后一小时的时间

     


    freeBSD:

    显示正常时间
    /bin/date -v -10M "+%Y%m%d%H%M"    //比当前时间提前10minutes的时间,返回结果:20090118043

    /bin/date -v 10M "+%Y%m%d%H%M"    //比当前时间晚10minutes的时间,返回结果:200901180410

    显示时间戳

    /bin/date -v 10M +%s         //比当前时间晚10minutes的时间戳,返回结果:1232223031

    /bin/date -v -10M +%s         //比当前时间晚10minutes的时间戳,返回结果:1232224962

    未来若干年的时间戳

    date +%s -d '2050-12-31 00:00:00' 


    收藏到:Del.icio.us