时间递增

def page_time(detester):

    date_list = []
    start_date = datetime.strptime(detester, "%Y%m%d")
    for x in range(30):
        one_day = dtd(1)
        start_date += one_day
        next_date = start_date.strftime("%Y%m%d")
        date_list.append(next_date)
    return  date_list

start = "20180101"
list_date = page_time(start)
print(list_date)

 

输入时间,每次递增一天,添加到一个列表中

 

每小时递增,获取两端时间每小时递增的值:

def getBetweenDay(begin_date, end_date):
    date_list = []
    begin_date = datetime.datetime.strptime(begin_date, "%Y%m%d%H")
    # end_date = datetime.datetime.strptime(time.strftime('%Y%m%d%H', time.localtime(time.time())), "%Y%m%d%H")
    end_date = datetime.datetime.strptime(end_date, "%Y%m%d%H")
    while begin_date <= end_date:
        date_str = begin_date.strftime("%Y%m%d%H")
        date_list.append(date_str)
        begin_date += datetime.timedelta(hours=1)
    return date_list

 

你可能感兴趣的:(个人日记)