格式化datetime.utcnow()时间

use*_*628 10 python datetime

我节省了时间 presentTime=datetime.datetime.utcnow()

它的输出是2014-08-18 21:11:35.537000.如何将其格式化为:2014年8月18日 - 21:11:35?

pok*_*oke 16

datetime.utcnow返回一个datetime对象.您可以使用其strftime方法将其转换为所需格式的字符串:

>>> datetime.datetime.utcnow().strftime('%B %d %Y - %H:%M:%S')
'August 20 2014 - 13:55:49'
Run Code Online (Sandbox Code Playgroud)