Python Calendar Module Summary

Source: Internet
Author: User
Tags string format


The functions of the Calendar module are calendar-related, provide some ways to manipulate dates, and generate calendars.

There are three main categories available in the Calendar module:

First, calendar. Calendar (firstweekday=0)

This class provides a number of generators, such as the day of the week builder, a month calendar generator

Second, calendar. Textcalendar (firstweekday=0)

This class provides a way to generate a calendar string by month, by year.

Third, calendar. Htmlcalendar (firstweekday=0)

Similar to Textcalendar, but produces an HTML-formatted calendar


The Calendar module itself also offers many methods:

1Calendar.calendar (year,w=2,l=1,c=6)

Returns the year calendar of a multi-line string format with a 3-month line with a distance of C. The daily width interval is w characters. The length of each line is 21* w+18+2* C. L is the number of rows per week.

Case:

{

Return calendar for one year

Calendar.calendar (2011,w=2,l=1,c=2)


}

2Calendar.firstweekday ()

Returns the settings for the current weekly start date. By default, 0 is returned when the Caendar module is first loaded, which is Monday.

Case:

{

Calendar.setfirstweekday (Calendar. SUNDAY) # # #默认每周的第一天是星期一, changed here to Sunday

' MONDAY ', ' SATURDAY ', ' SUNDAY ', ' Thursday ', ' Tuesday ', ' Textcalendar ', ' timeencoding ', ' Wednesday '

}

3calendar.isleap (year)

is a leap year that returns true, otherwise false.

Case:

{

Calendar.isleap (2017)

}

4calendar.leapdays (y1,y2)

Returns the total number of leap years between y1,y2 two.

Case:

{

Calendar.leapdays (2000,2020); # 5

}

5Calendar.month (year,month,w=2,l=1)

Returns a multi-line string format for year month calendar, two row headings, and one week row. The daily width interval is w characters. The height of each row is 7* w+6. L is the number of rows per week.

Case:

{

Returns the calendar of a month, the return type is a string type

Calendar.month (11,w=4,l=2);

}

6Calendar.monthcalendar (year,month)

Returns a single-level nested list of integers. Each sub-list is loaded with integers representing one weeks. The date of year month is set to 0, and the day of the month is indicated by the day of the week, starting from 1.

Case:

{

Calendar.monthcalendar (2017,3)

##[[0, 0, 0, 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, 31, 0]]


}

7Calendar.monthrange (year,month)

Returns a two integer. The first is the day of the week of the month, and the second is the date code for that month. Day from 0 (Monday) to 6 (Sunday); The month is from 1 to 12.

Case:

{

Calendar.monthrange (2017,3); # # (2, 31)

}

8calendar.prcal (year,w=2,l=1,c=6)

Equivalent to print Calendar.calendar (year,w,l,c).

Case:

{

Calendar.prcal (2017,w=2,l=1,c=6)

}

9Calendar.prmonth (year,month,w=2,l=1)

Equivalent to print Calendar.calendar (year,w,l,c).

Case:

{

Calendar.prmonth (2017,3,w=2,l=1)

}

TenCalendar.setfirstweekday (weekday)

Set the starting date code for the week. 0 (Monday) to 6 (Sunday).

Case:

{

Calendar.setfirstweekday (Calendar. SUNDAY) # # #默认每周的第一天是星期一, changed here to Sunday

' MONDAY ', ' SATURDAY ', ' SUNDAY ', ' Thursday ', ' Tuesday ', ' Textcalendar ', ' timeencoding ', ' Wednesday '

}

calendar.timegm (tupletime)

In contrast to Time.gmtime: accepts a time tuple form, returning the time suffix (the number of floating-point seconds elapsed after the 1970 era).

Case:

{

Calendar.timegm (Time.localtime (Time.time ()) # # # #1489616168

}

Calendar.weekday (year,month,day)

Returns the date code for the given date. 0 (Monday) to 6 (Sunday). The month is 1 (January) to 12 (December).

Case:

{

Calendar.weekday (2017,3,1); # #2

}


Properties of the Calendar module

Calendar.day_name, Calendar.day_abbr, Calendar.month_name, CALENDAR.MONTH_ABBR

by changing these properties, you can modify the text that displays the week and month


Other related modules and functions

In Python, other modules that handle the date and time are:

DateTime module

Pytz Module

Dateutil Module

This article is from the "Silent Dialogue" blog, please be sure to keep this source http://chbinmile.blog.51cto.com/6085145/1907030

Python Calendar Module Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.