我需要增加日期時間值的月份next_month = datetime.datetime(mydate.year, mydate.month+1, 1)當(dāng)月份為12時,它將變?yōu)?3并引發(fā)錯誤“月份必須在1..12中”。(我希望這一年會增加)我想使用timedelta,但不需要月份參數(shù)。有relativedelta python軟件包,但我不想僅為此安裝它。還有一種使用strtotime的解決方案。time = strtotime(str(mydate));next_month = date("Y-m-d", strtotime("+1 month", time));我不想從datetime轉(zhuǎn)換為str然后轉(zhuǎn)換為time,然后轉(zhuǎn)換為datetime;因此,它仍然還是一個圖書館有人像使用timedelta一樣有任何簡單的好解決方案嗎?
添加回答
舉報
0/150
提交
取消