【问题标题】:epoch time to datetime conversion python纪元时间到日期时间转换python
【发布时间】:2019-02-04 23:12:04
【问题描述】:

我正在使用 python 3.6.2 并尝试使用以下方法将纪元转换为日期时间,

creation_date=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(epoch)

我收到以下错误,

OSError: [Errno 22] Invalid argument

“1535539535018”失败。

【问题讨论】:

  • time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) 非常适合我。你用的是什么时代?这将工作任意秒数
  • “1535539535018”失败
  • @Onyambu,没错!

标签: python-3.x epoch


【解决方案1】:

您应该确保您的纪元时间以秒为单位:

 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1535539535018/1000))

【讨论】:

    猜你喜欢
    • 2017-06-22
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    • 2018-04-24
    • 2011-12-06
    • 1970-01-01
    • 2020-04-24
    相关资源
    最近更新 更多