python怎么获取当前时间年月日?

Python015

python怎么获取当前时间年月日?,第1张

取得时间相关的信息的话,要用到python time模块,python time模块里面有很多非常好用的功能,你可以去官方文档了解下,要取的当前时间的话,要取得当前时间的时间戳,时间戳好像是1970年到现在时间相隔的时间。你可以试下下面的方式来取得当前时间的时间戳:import timeprint time.time()

对的,你把下标用错了而已,应该为days[1] += 1 ,才是润二月的29天。

year = int(input('year:\n'))

month = int(input('month:\n'))

day = int(input('day:\n'))

days = [31,28,31,30,31,30,31,31,30,31,30,31]

if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):

    days[1] += 1

now = sum(days[0:month-1])+day

print(now)