import arrow date_list = [] for year in [2019, 2020, 2021]: # 年份 start_date = '%s-1-1' % year a = 0 if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): days_sum = 366 else: days_sum = 365 while a < days_sum: b = arrow.get(start_date).shift(days=a).format("YYYY-MM-DD") a += 1 date_list.append(b) for date in date_list: print(date)
日期转换
import time import datetime # 当前时间的标准格式 now_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") print(now_time) # 当前时间的时间戳 time_stamp = int(time.time()) print(time_stamp) # 时间错转标准时间格式 a = 1632300494 b = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(a)) print(b)
import time # 将日期格式补全 a = "2010-5-28" b = time.strftime("%Y-%m-%d", time.strptime(a, "%Y-%m-%d")) print(b) # 日期格式转时间戳 c = int(time.mktime(time.strptime(a, "%Y-%m-%d"))) print(c)