如何将python日期时间转换为具有可读格式日期的字符串?

How do I turn a python datetime into a string, with readable format date?

1
2
3
4
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

我怎么把它变成一根绳子?:

1
"January 28, 2010"


(P)数据类已经成为一种方法The Python docs documents the different formats it accepts:(p)

  • Python 2:Strftime(……)Behavior
  • Python 3:Strftime(……)Behavior

(P)对于这一具体的例子,它会看到一些类似的:(p)字母名称


(P)这是你如何能够同意同样使用Python's general formating function…(p)字母名称(P)The formating characters used here are the same as those used by strftime.Don't miss the leading EDOCX1 in the format specifier.(p)(P)Using format(……)instead of strftime(……)in most cases can make the code more readable,easier to write and consistent with the way formated output is generatiated…(p)字母名称(P)Compare the above with the following strftime(……)alternative…(p)字母名称(P)Moreover,the following is not going to work…(p)字母名称(P)And so on…(p)


Using F-Strings,in Python 3.6+.字母名称


(P)很老的问题,我知道。但是,随着新的F-Strings(starting from Python 3.6)出现了一些新的选择。So here for completeness:(p)字母名称(P)EDOCX1音标和EDOCX1音标2音标behavior explains what the format specifiers mean.(p)


(P)Read strfrtime from the official docs.(p)


(P)Python datetime object has a method attribute,which prints in readable format.(p)字母名称


(P)这是日期的格式吗?(p)字母名称