如何将Javascript new Date().toutString()生成Python

2024-10-01 04:51:03 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在Javascript上以new Date().toutstring()的形式获取python结果?在

在我制作的Javascript上:

new Date().toUTCString()
"Tue, 08 Sep 2015 09:45:32 GMT"

在Python上

^{pr2}$

Tags: newdatejavascriptsep形式gmttuepr2
3条回答

时间格式类似于RFC 2822 format (used in emails)

>>> import email.utils
>>> email.utils.formatdate(usegmt=True)
'Tue, 08 Sep 2015 10:06:04 GMT'

或者,您可以使用^{}获得所需的任何时间格式:

^{pr2}$

其中^{} is defined here。在

    import datetime
    date = datetime.datetime.utcnow().strftime("%c")
    print date # >>> 'Tue Sep  8 10:14:17 2015'`

试试这个。。在

from datetime import datetime
date = datetime.utcnow().ctime()
print date # >>> 'Tue Sep  8 10:10:22 2015'

相关问题 更多 >