How to get the last day of the month?

后端 未结 30 2983
迷失自我
迷失自我 2020-11-22 06:13

Is there a way using Python\'s standard library to easily determine (i.e. one function call) the last day of a given month?

If the standard library doesn\'t support

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 07:03

    In Python 3.7 there is the undocumented calendar.monthlen(year, month) function:

    >>> calendar.monthlen(2002, 1)
    31
    >>> calendar.monthlen(2008, 2)
    29
    >>> calendar.monthlen(2100, 2)
    28
    

    It is equivalent to the documented calendar.monthrange(year, month)[1] call.

提交回复
热议问题