2014-11-05 53 views
-3

我试过这些代码:
我想返回格式化的字符串,是一天加一。Python日期时间格式化字符串

import datetime 
from datetime import timedelta 

d = datetime.date(2014, 11, 2) 

dPlusOne = d + timedelta(days=1) 

print dPlusOne.strftime("%d/%m/%y") 

但有一些错误:

AttributeError: 'module' object has no attribute 'strftime' 
+2

给出在Python 3 – 2014-11-05 09:21:17

+0

这一切的权利 – Hackaholic 2014-11-05 09:23:03

+0

但我真的面对这个问题的代码不会提高对Python的2和其他(SyntaxError错误)的任何错误代码。 WTF你们否定了这个问题。 – jjLin 2014-11-05 09:24:52

回答

0

这个工作对我来说:

from datetime import timedelta, date 

d = date(2014, 11, 2) 
dPlusOne = d + timedelta(days=1) 

print dPlusOne.strftime("%d/%m/%y") 

输出继电器:

03/11/14 

参见:

enter image description here

+0

但我仍然错误: AttributeError:struct_time – jjLin 2014-11-05 09:23:52