How to get the last day of the month?

后端 未结 30 3026
迷失自我
迷失自我 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:12

    EDIT: See @Blair Conrad's answer for a cleaner solution


    >>> import datetime
    >>> datetime.date(2000, 2, 1) - datetime.timedelta(days=1)
    datetime.date(2000, 1, 31)
    

提交回复
热议问题