zoukankan      html  css  js  c++  java
  • shell关于日期的加减

    $cat sh.sh 
    #!/bin/bash
    
    if [ $# == 0 ] ; then
        ydate=`date -d -1days "+%Y%m%d"`
        ydateother=`date -d -1days "+%Y-%m-%d"`
        tdate=`date -d -0days "+%Y%m%d"`
        tdateother=`date -d -0days "+%Y-%m-%d"`
    elif [ $# == 1 ] ; then 
        ydate=$1
        ydateother=`date -d ${ydate} +"%Y-%m-%d"`
        tdate=`date -d "${ydate} 1days" +"%Y%m%d"`
        tdateother=`date -d ${tdate} +"%Y-%m-%d"`
    elif [ $# == 2 ] ; then 
        ydate=$1
        ydateother=`date -d ${ydate} +"%Y-%m-%d"`
        tdate=$2
        tdateother=`date -d ${tdate} +"%Y-%m-%d"`
    else
        echo "please do not input if calcute yedterday."
        echo "please input like if calcute 20170510 one day: 20170510"
        echo "please input like if calcute 20170510 and 20170512 two days : 20170510 20170511"
        exit -1
    fi 
    echo ${ydate}'--'${ydateother}'--'${tdate}'---'${tdateother}

    传入字符串,修改为日期;

    根据传入的字符串识别的日期,进行加减

  • 相关阅读:
    JQuery实现数组移除指定元素
    美团酒旅面经
    搜狗一面
    360面经
    头条面经
    搜狐笔试题
    kolakoski序列
    函数的节流
    隐藏元素的几种方法
    移动端适配与响应式布局
  • 原文地址:https://www.cnblogs.com/zhzhang/p/6846300.html
Copyright © 2011-2022 走看看