Py学习  »  Python

在python中递增月份,然后打印递增月份的名称

Kaushal • 6 年前 • 1783 次点击  

有没有办法打印递增月份的名称?

import datetime
currentDT = datetime.datetime.now()
currentmonth=currentDT.strftime("%B")
nextmonth = datetime.date.today().month + 1

这里我得到整数形式的“下一个月”。

7

但是我怎样才能知道那个月的名字,也就是七月。我甚至试过用这个,

next_month=nextmonth.strftime("%B")

但它返回了错误,

AttributeError: 'int' object has no attribute 'strftime'
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/34310
 
1783 次点击  
文章 [ 4 ]  |  最新文章 6 年前