计算上月并且返回格式为xx


要求计算上月,并且返回格式为XX的

now = datetime.datetime.now()
last = now - datetime.timedelta(days=now.day)
print last.strftime('%m')

计算下个月

import calendar
import datetime

now = datetime.datetime.now()
max_days = calendar.monthrange(now.year, now.month)[1]
next = now + datetime.timedelta(days=max_days - now.day + 1)
print next.strftime('%m')


上篇: libpq-fe.h:没有那个文件或目录 下篇: 线程里的全局变量threading.local