How to get the last day of the month?

后端 未结 30 2583
迷失自我
迷失自我 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 06:53

    import datetime
    
    now = datetime.datetime.now()
    start_month = datetime.datetime(now.year, now.month, 1)
    date_on_next_month = start_month + datetime.timedelta(35)
    start_next_month = datetime.datetime(date_on_next_month.year, date_on_next_month.month, 1)
    last_day_month = start_next_month - datetime.timedelta(1)
    

提交回复
热议问题