Python中如何根据日期区间进行循环

=Start=

缘由:

学习、提高需要

正文:

参考解答:

python datetime for loop

import datetime
 
date1 = datetime.date(2017725)
date2 = datetime.date(2017818)
day = datetime.timedelta(days=1)
while date1 <= date2:
    print date1.strftime('%Y.%m.%d')
    date1 = date1 + day

&

如何用Bash确定每个月的英文缩写?
先给结果:
('Jan''Feb''Mar''Apr''May''Jun''Jul''Aug''Sep''Oct''Nov''Dec',)
再说方法:
for i in $(seq 0 11);do
    date -d "2017-01-01 + "$i" month" -R | awk '{print $3}'
done

https://ixyzero.com/blog/archives/3055.html

参考链接:

https://stackoverflow.com/questions/14288498/creating-a-loop-for-two-dates
https://stackoverflow.com/questions/1060279/iterating-through-a-range-of-dates-in-python
https://stackoverflow.com/questions/22907062/iterating-over-date-in-python

=END=

声明: 除非注明,ixyzero.com文章均为原创,转载请以链接形式标明本文地址,谢谢!
https://ixyzero.com/blog/archives/3573.html

《Python中如何根据日期区间进行循环》上有1条评论

  1. Python中如何将 timestamp 转换成 ‘年-月-日’ 的格式?
    http://www.jb51.net/article/130259.htm
    https://docs.python.org/2/library/datetime.html#datetime.datetime.fromtimestamp
    https://stackoverflow.com/questions/26161156/python-converting-string-to-timestamp-with-microseconds

    import datetime
    seconds = time.time()
    datetime.datetime.fromtimestamp(seconds).strftime("%Y-%m-%d %H:%M:%S")
    micro_seconds = 1526306450784
    datetime.datetime.fromtimestamp(micro_seconds / 1000.0).strftime("%Y-%m-%d %H:%M:%S")

发表评论

电子邮件地址不会被公开。 必填项已用*标注