下面 hello 是开始时间, world 是结束时间
#!/bin/bash START=$(date +%s); hello="20160911 00" world="20160911 03" datebegin=`date -d "$hello" "+%Y%m%d%H"` dateend=`date -d "$world" "+%Y%m%d%H"` while [ "$datebegin" -le "$dateend" ] do echo $datebegin echo $datebegin >> test.txt middle=" " before=`echo $datebegin | cut -c 1-8` after=`echo $datebegin | cut -c 9-10` tmp="$before$middle$after" datebegin=`date -d "$tmp +1 hour " +%Y%m%d%H` done END=$(date +%s); echo $((END-START)) | awk ‘{print int($1/3600)":"int($1%3600/60)":"int($1%3600%60)}‘
时间: 2024-10-29 07:39:46