【问题标题】:python strftime not working with hours minutes and secondspython strftime不适用于小时分钟和秒
【发布时间】:2016-07-19 10:35:13
【问题描述】:

我在这里阅读官方文档

https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior

它说我可以使用

%H 和 %M 和 %S 表示小时、分钟和秒

我这样做:

datetime.date.today().strftime("%Y-%m-%d %H:%M:%S")

我总是得到

'2016-07-18 00:00:00'

值在哪里?

【问题讨论】:

    标签: python datetime


    【解决方案1】:

    您要的是一个不包括时间的日期。你想要一个日期时间:

    datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    

    例子:

    In [3]: datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    Out[3]: '2016-07-18 18:26:18'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-30
      • 2021-09-17
      • 1970-01-01
      • 2012-06-08
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      相关资源
      最近更新 更多