循环输出两个日期间的日期
shell#!/bin/bashstart_date="20210917"end_date="20211116"while [ "$start_date" -le "$end_date" ];dostat_date=`date -d "$start_date" +%Y-%m-%d`echo $stat_datestart_date=$(date -d "$start_date+1days" +%Y
·
shell
#!/bin/bash
start_date="20210917"
end_date="20211116"
while [ "$start_date" -le "$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
python
# 方法1:
import datetime
def main():
begin = datetime.date(2014,6,1)
end = datetime.date(2014,6,7)
for i in range((end - begin).days+1):
day = begin + datetime.timedelta(days=i)
print str(day)
if __name__ == '__main__':
main()
# 方法2:
import datetime
begin = datetime.date(2014,6,1)
end = datetime.date(2014,6,7)
d = begin
delta = datetime.timedelta(days=1)
while d <= end:
print d.strftime("%Y-%m-%d")
d += delta
# 方法3:
import datetime
def daterange(d1, d2):
return (d1 + datetime.timedelta(days=i) for i in range((d2 - d1).days + 1))
更多推荐
已为社区贡献2条内容
所有评论(0)