HTMLCalendar().formatmonth

Calendar Module

formatmonth(theyear, themonth, withyear=True)
theyearYear number for which calendar of the month is returned
themonthYear number for which calendar of the month is returned
withyearOptional, to include Year in header
HTMLCalendar() : returns Monthly Calendar using HTML tags

import calendar
x=calendar.HTMLCalendar()
x.formatmonth(theyear=2020,themonth=7,withyear=True)
Output
<table border="0" cellpadding="0" cellspacing="0" class="month">\n
<tr><th colspan="7" class="month">July 2020</th></tr>\n
<tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>\n
<tr><td class="noday"> </td><td class="noday"> </td><td class="wed">1</td><td class="thu">2</td><td class="fri">3</td><td class="sat">4</td><td class="sun">5</td></tr>\n
<tr><td class="mon">6</td><td class="tue">7</td><td class="wed">8</td><td class="thu">9</td><td class="fri">10</td><td class="sat">11</td><td class="sun">12</td></tr>\n
<tr><td class="mon">13</td><td class="tue">14</td><td class="wed">15</td><td class="thu">16</td><td class="fri">17</td><td class="sat">18</td><td class="sun">19</td></tr>\n
<tr><td class="mon">20</td><td class="tue">21</td><td class="wed">22</td><td class="thu">23</td><td class="fri">24</td><td class="sat">25</td><td class="sun">26</td></tr>\n
<tr><td class="mon">27</td><td class="tue">28</td><td class="wed">29</td><td class="thu">30</td><td class="fri">31</td><td class="noday"> </td><td class="noday"> </td></tr>\n
</table>\n
July 2020
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
2728293031  
Based on the setting of first day of the week, the calendar first weekday can be set. Week day number starts from 0 as Monday , 1 as Tuesday and ends at 6 as Sunday.
import calendar
x=calendar.HTMLCalendar()
x.setfirstweekday(4) # first week day is Friday
x.formatmonth(theyear=2020,themonth=7,withyear=True)
Output
'<table border="0" cellpadding="0" cellspacing="0" class="month">\n
<tr><th colspan="7" class="month">July 2020</th></tr>\n<tr><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th></tr>\n
<tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="wed">1</td><td class="thu">2</td></tr>\n
<tr><td class="fri">3</td><td class="sat">4</td><td class="sun">5</td><td class="mon">6</td><td class="tue">7</td><td class="wed">8</td><td class="thu">9</td></tr>\n
<tr><td class="fri">10</td><td class="sat">11</td><td class="sun">12</td><td class="mon">13</td><td class="tue">14</td><td class="wed">15</td><td class="thu">16</td></tr>\n
<tr><td class="fri">17</td><td class="sat">18</td><td class="sun">19</td><td class="mon">20</td><td class="tue">21</td><td class="wed">22</td><td class="thu">23</td></tr>\n
<tr><td class="fri">24</td><td class="sat">25</td><td class="sun">26</td><td class="mon">27</td><td class="tue">28</td><td class="wed">29</td><td class="thu">30</td></tr>\n
<tr><td class="fri">31</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr>\n
</table>\n'
July 2020
FriSatSunMonTueWedThu
     12
3456789
10111213141516
17181920212223
24252627282930
31      
Calendar Module in Python itermonthdays() itermonthdays2() itermonthdays3()




plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer