python calendar.HTMLCalendar

前端 未结 5 1026
面向向阳花
面向向阳花 2021-02-02 04:10

I think I want to use pythons built in calendar module to create an HTML calendar with data. I say I think because I\'ll probably think of a better way, but right now it\'s a l

5条回答
  •  暖寄归人
    2021-02-02 04:37

    The calendar module has usually been pretty useless, but in 2.5 it introduced the Calendar object. This won't render an HTML calendar for you, but it has loads of methods that will help you render a calendar.

    For example, monthdatescalendar(year, month) will give you a list of all weeks in the month given, where each week in turn is a list of the seven days. So monthdatescalendar(2009,7) will start with [[datetime.date(2009, 6, 29), datetime.date(2009, 6, 30), and end with datetime.date(2009, 8, 1), datetime.date(2009, 8, 2)]]

    With this, it then becomes a trivial exercise to generate the HTML you want.

提交回复
热议问题