Last active
November 5, 2018 08:44
-
-
Save RRRoger/d2f45a3db441bacf8947283c76141471 to your computer and use it in GitHub Desktop.
获取一个时间区间的list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def date_range(begin_date, end_date): | |
""" | |
获取一个时间区间的list | |
""" | |
dates = [] | |
dt = datetime.datetime.strptime(begin_date, "%Y-%m-%d") | |
date = begin_date[:] | |
while date <= end_date: | |
dates.append(date) | |
dt = dt + datetime.timedelta(1) | |
date = dt.strftime("%Y-%m-%d") | |
return dates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment