如何将 python 日期时间转换为字符串,具有可读格式的日期?
问题描述:
t = e['updated_parsed']
dt = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],t[6]
print dt
>>>2010-01-28 08:39:49.000003
如何将其转换为字符串?:
How do I turn that into a string?:
"January 28, 2010"
答
datetime 类有一个方法 strftime.Python 文档记录了它接受的不同格式:
The datetime class has a method strftime. The Python docs documents the different formats it accepts:
- Python 2:strftime() 行为
- Python 3:strftime() 行为
对于这个特定的例子,它看起来像:
For this specific example, it would look something like:
my_datetime.strftime("%B %d, %Y")