zoukankan      html  css  js  c++  java
  • mikadonic-获得前几天系统日期适用linux和aix

    #!/usr/bin/ksh
    #################config#######################################
    DATE=`date +%Y%m%d`
    BEFORE=10
    ##############################################################
    month=`echo $DATE|cut -c 5-6`
    day=`echo $DATE|cut -c 7-8`
    year=`echo $DATE|cut -c 1-4`

    # Add 0 to month. This is a
    # trick to make month an unpadded integer.
    # month=`expr $month - 0`

    # Subtract one from the current day.
    day=`expr $day - $BEFORE`

    # If the day is 0 then determine the last
    # day of the previous month.
    if [ $day -eq 0 ]; then
    # Find the preivous month.
    month=`expr $month - 1`
    # If the month is 0 then it is Dec 31 of
    # the previous year.
    if [ $month -eq 0 ]; then
    month=12
    day1=31
    year=`expr $year - 1`

    # If the month is not zero we need to find
    # the last day of the month.
    else
    case $month in
    1|3|5|7|8|10|12) day1=31;;
    4|6|9|11) day1=30;;
    2)
    if [ `expr $year % 4` -eq 0 a `expr $year % 100` % -ne 0 o `expr $year % 400` -eq 0 ]; then
    day1=29
    else
    day1=28
    fi
    ;;
    esac
    day=`expr $day1 - $day`
    fi
    fi

    if [ $day -lt 0 ]; then
    # Find the preivous month.
    month=`expr $month - 1`
    # If the month is 0 then it is Dec 31 of
    # the previous year.
    if [ $month -eq 0 ]; then
    month=12
    day=`expr 31 + $day`
    year=`expr $year - 1`
    # If the month is not zero we need to find
    # the last day of the month.
    else
    case $month in
    1|3|5|7|8|10|12) day1=31;;
    4|6|9|11) day1=30;;
    2)
    if [ `expr $year % 4` -eq 0 a `expr $year % 100` % -ne 0 o `expr $year % 400` -eq 0 ]; then
    day1=29
    else
    day1=28
    fi
    ;;
    esac
    day=`expr $day1 + $day`
    fi
    fi

    daylen=`expr length $day`
    monthlen=`expr length $month`
    if [ $daylen -lt 2 ];then
    day=0$day
    fi
    if [ $monthlen -lt 2 ];then
    month=0$month
    fi
    echo $year$month$day

  • 相关阅读:
    BZOJ 3513: [MUTC2013]idiots(fft)
    BZOJ 2194: 快速傅立叶之二(fft)
    BZOJ 3779: 重组病毒(线段树+lct+树剖)
    LUOGU P3723 [AH2017/HNOI2017]礼物 (fft)
    CF 622F (拉格朗日插值)
    LUOGU P4781 【模板】拉格朗日插值
    bzoj 4184 shallot——线段树分治+线性基
    51nod 1673 树有几多愁——虚树+状压DP
    bzoj 3611(洛谷 4103) [Heoi2014]大工程——虚树
    bzoj 2286(洛谷 2495) [Sdoi2011]消耗战——虚树
  • 原文地址:https://www.cnblogs.com/MiKaDoNik/p/8795422.html
Copyright © 2011-2022 走看看