shell日期循环

linux

start_date="20180726"
end_date="20180830"

while [ "$start_date" != "$end_date" ];
do
  stat_date=`date -d "$start_date" +%Y-%m-%d`
  echo $stat_date
  start_date=$(date -d "$start_date+1days" +%Y%m%d)
done

mac

begin="2019-04-02"
begin=`date -j -f %Y-%m-%d $begin +%s`

for (( i = 0; i < 35; i++ )); do
    current=`date -r $(expr $begin + $i \* 86400) +"%Y-%m-%d"`
    year=${current:0:4}
    month=${current:5:2}
    day=${current:8:2}
    echo $current
done

posted @ 2019-05-06 16:57  田小样  阅读(422)  评论(1编辑  收藏  举报