我需要增加日期时间值的月份
next_month = datetime.datetime(mydate.year, mydate.month+1, 1)
Run Code Online (Sandbox Code Playgroud)
当月份为12时,它变为13并且引发错误"月份必须在1..12".(我预计这一年会增加)
我想使用timedelta,但它不需要一个月的论点.有relativedelta python包,但我不想只为此安装它.还有使用strtotime的解决方案.
time = strtotime(str(mydate));
next_month = date("Y-m-d", strtotime("+1 month", time));
Run Code Online (Sandbox Code Playgroud)
我不想将datetime转换为str然后转换为time,然后转换为datetime; 因此,它仍然是一个图书馆
有没有人像使用timedelta一样有任何好的和简单的解决方案?