5.2 calendar--General Date correlation function (1)

Source: Internet
Author: User

This module provides a general date-related operation function for the calendar. By default, Monday is the first day of the week, and Sunday is the last day of the week. the first day of the week can be set by the function setfirstweekday () function, for example, parameter input 6 is Sunday as the first day.

Class Calendar. Calendar (firstweekday=0)

Creates a Calendar object. The parameter firstweekday is an integer that indicates the day of the week on which the first week begins. 0 means Monday,6 means Sunday.

Example:

#python 3.4

Import Calendar

Cal = Calendar. Calendar (0)

Print (CAL)

The resulting output is as follows:

<calendar. Calendar Object at 0x02a30e30>

the Calendar class has the following instance methods:

Iterweekdays ()

Returns the iteration object of the week, typically used to output the daily ordinal of a week. The default is starting from 0 .

Example:

#python 3.4

Import Calendar

Cal = Calendar. Calendar (0)

Print (CAL)

Print (Cal.iterweekdays ())

For I in Cal.iterweekdays ():

Print (i)

The resulting output is as follows:

<calendar. Calendar Object at 0x02a50e30>

<generator Object Iterweekdays at 0x02ceb8c8>

0

1

2

3

4

5

6

Itermonthdates (year, month)

Returns the relevant date for the specified year and month, starting on the first day of the specified week of the month, and the day ending in the last week of the month.

Example:

#python 3.4

Import Calendar

Cal = Calendar. Calendar (0)

Print (CAL)

Print (Cal.itermonthdates (2015, 11))

For I in Cal.itermonthdates (2015, 11):

Print (i, end = ', ')

The resulting output is as follows:

<calendar. Calendar Object at 0x02d00e30>

<generator Object Itermonthdates at 0x02d6b8c8>

2015-10-26,2015-10-27,2015-10-28,2015-10-29,2015-10-30,2015-10-31,2015-11-01,2015-11-02,2015-11-03,2015-11-04,2015-11-05 , 2015-11-06,2015-11-07,2015-11-08,2015-11-09,2015-11-10,2015-11-11,2015-11-12,2015-11-13,2015-11-14,2015-11-15,2015-11-16 , 2015-11-17,2015-11-18,2015-11-19,2015-11-20,2015-11-21,2015-11-22,2015-11-23,2015-11-24,2015-11-25,2015-11-26,2015-11-27 , 2015-11-28,2015-11-29,2015-11-30,2015-12-01,2015-12-02,2015-12-03,2015-12-04,2015-12-05,2015-12-06,

ITERMONTHDAYS2 (year, month)

Returns a one-month effective date, grouped by a tuple (date, week), by week.

Example:

#python 3.4

Import Calendar

Cal = Calendar. Calendar (0)

Print (CAL)

For I in Cal.itermonthdays2 (2015, 11):

Print (i, end = ', ')

The resulting output is as follows:

<calendar. Calendar Object at 0x02ce0e30>

(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 6), (2, 0), (3, 1), (4, 2), (5), (3, 6), (4, 7), (5, 8), (6, 9), (0, 10), (1, 11), ( 12, 3), (13, 4), (14, 5), (15, 6), (16, 0), (17, 1), (18, 2), (19, 3), (20, 4), (21, 5), (22, 6), (23, 0), (24, 1), (25, 2), (26 , 4), (28, 5), (29, 6), (30, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6),

Itermonthdays (year, month)

Returns all dates for the specified year and month.

Example:

#python 3.4

Import Calendar

Cal = Calendar. Calendar (0)

Print (CAL)

For I in Cal.itermonthdays (2015, 11):

Print (i, end = ', ')

The resulting output is as follows:

<calendar. Calendar Object at 0x02c80e30>

0,0,0,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,0,0,0,0,0,0,

Monthdatescalendar (year, month)

Returns all dates for the specified year and month, generates a list once a week, and then returns a large list.

Example:

#python 3.4

Import Calendar

Cal = Calendar. Calendar (0)

For I in Cal.monthdatescalendar (2015, 11):

Print (i)

Print (';')

The resulting output is as follows:

[Datetime.date], datetime.date (+, +), datetime.date (+), datetime.date (+, +), Datet ". Ime.date (+), Datetime.date (2015, 11, 1), datetime.date (+)

;

[Datetime.date, one, 2], datetime.date (3), Datetime.date (one, one, 4), Datetime.date (one, one, 5), DateTime. Date (6), Datetime.date (7), Datetime.date (2015, 11, 8)]

;

[Datetime.date, one, 9], datetime.date (one, one, ten), Datetime.date (one, one, one), Datetime.date (one, one, one), Dateti Me.date, Datetime.date (2015, 11, 15), datetime.date (+/-)

;

[Datetime.date, one, +], datetime.date (one, one, +), datetime.date (one, one, each), Datetime.date (one, one, each), Datet Ime.date, Datetime.date (2015, 11, 22)], datetime.date (+).

;

[Datetime.date, one, all], datetime.date (one, one, each), Datetime.date (one, one, and a), datetime.date (.), Datet Ime.date, Datetime.date (2015, 11, 29)], Datetime.date (+).

;

[Datetime.date, Datetime.date, 1], datetime.date (+, 2), Datetime.date (+, 3), DateTime, (+) . Date (4), Datetime.date (5), Datetime.date (2015, 12, 6)]

;

Cai Junsheng qq:9073204 Shenzhen

5.2 calendar--General Date correlation function (1)

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.