Python Calendar Module

Source: Internet
Author: User
Tags string format

Calendar Module

The functions of this module are calendar-related, such as printing a month's character calendar.

Monday is the default first day of the week, and Sunday is the default last day.

You need to call the calendar.setfirstweekday () function to change the settings. The module contains the following built-in functions:

Serial Number Functions and descriptions
1 Calendar.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.
2 Calendar.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.
3 Calendar.isleap (year)
is a leap year that returns true, otherwise false.
4 Calendar.leapdays (Y1,y2)
Returns the total number of leap years between y1,y2 two.
5 Calendar.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 length of each line is 7* w+6. L is the number of rows per week.
6 Calendar.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.
7 Calendar.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.
8 Calendar.prcal (year,w=2,l=1,c=6)
Equivalent to print Calendar.calendar (year,w,l,c).
9 Calendar.prmonth (year,month,w=2,l=1)
Equivalent to print Calendar.calendar (year,w,l,c).
10 Calendar.setfirstweekday (Weekday)
Set the starting date code for the week. 0 (Monday) to 6 (Sunday).
11 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).
12 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).
simple implementation of a specified date calendar Code Implementation
# Import Calendar Module Import Calendar # Enter the specified year yy = Int (input (' Enter year:'))#  Enter the specified month mm = int (input (' Enter month:'))#  Prints the calendar print ( Calendar.month (yy, mm))
Execution Results
Please enter the year: 2018 Enter Month:   2018Mo Tu We Th Fr Sa Su                1  2 3  4  5  6  7  8  910 11 12 13 14 15 1617 18 19 20 21 22 2324 25 26 27 28 29 3031

Calendar also has many other feature parameters, which are simply implemented to print a specified date calendar.

Python Calendar Module

Related Article

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.