首页 > 代码库 > python_日历 list_5

python_日历 list_5

>>> import datetime
>>> Today=datetime.date.today()
>>> Today
datetime.date(2017, 5, 24)
>>> Today-datetime.date(Today.year,1,1)+datetime.timedelta(days=1)
datetime.timedelta(144)
>>> datetime.date(Today.year,1,1)
datetime.date(2017, 1, 1)
>>> datetime.timedelta(days=1)
datetime.timedelta(1)
>>> Today.timetuple().tm_yday
144
>>> Today.replace(year=2013)
datetime.date(2013, 5, 24)
>>> Today.replace(month=1)
datetime.date(2017, 1, 24)
>>> now=datetime.datetime.now()
>>> now
datetime.datetime(2017, 5, 24, 12, 44, 51, 448321)
>>> now.replace(second=30)
datetime.datetime(2017, 5, 24, 12, 44, 30, 448321)
>>> now+datetime.timedelta(days=5)
datetime.datetime(2017, 5, 29, 12, 44, 51, 448321)

>>> now+datetime.timedelta(weeks=-5)
datetime.datetime(2017, 4, 19, 12, 44, 51, 448321)

 

>>> import calendar
>>> print(calendar.calendar(2017))
2017

January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 1 2 3 4 5 1 2 3 4 5
2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12
9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19
16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26
23 24 25 26 27 28 29 27 28 27 28 29 30 31
30 31

April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 1 2 3 4 5 6 7 1 2 3 4
3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
24 25 26 27 28 29 30 29 30 31 26 27 28 29 30

July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 1 2 3 4 5 6 1 2 3
3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
31

October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 31

>>> print(calendar.month(2016,4))
April 2016
Mo Tu We Th Fr Sa Su
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30

>>> calendar.isleap(2016)
True
>>> calendar.weekday(2017,5,24)
2

技术分享

python_日历 list_5