【问题标题】:How to print the current time in the format Day, Date Month Year HH:MM:SS?如何以日、日月年 HH:MM:SS 格式打印当前时间?
【发布时间】:2018-02-06 00:58:25
【问题描述】:

如何以Day, Date Month Year HH:MM:SS格式打印当前时间

Mon, 28 Aug 2017 15:37:01 .

然后,将此时间戳转换为纪元秒数,反之亦然。

【问题讨论】:

标签: python-2.7 datetime epoch


【解决方案1】:

datetime 模块完成所有工作

>>> import datetime
>>> datetime.datetime.now().strftime("%a, %d %B %Y %H:%M:%S")
'Tue, 29 August 2017 03:04:21'

【讨论】:

  • %I 是 12 小时 AM/PM 格式的时间。要获取 24 小时格式的小时数,请使用 %H
  • 你是怎么得到相同的但是在 UTC 中,这个是打印本地时间
  • @VijayKumar datetime.datetime.utcnow().strftime("%a, %d %B %Y %H:%M:%S") UTC
猜你喜欢
  • 2014-11-29
  • 1970-01-01
  • 2018-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
  • 1970-01-01
  • 2015-04-29
相关资源
最近更新 更多