【问题标题】:Elastic Beanstalk not running strptime as expectedElastic Beanstalk 未按预期运行 strptime
【发布时间】:2020-04-01 20:27:01
【问题描述】:

我在 Elastic Beanstalk 上运行 python 3.6。当我尝试使用 strptime 时出现以下错误:

ValueError: time data '2020-03-01 13:31:00 EST' does not match format '%Y-%m-%d %H:%M:%S %Z'

仅从该错误中,您可以看到时间数据与格式匹配。这是否比表面上看起来更多?我的代码如下:

r['SCHEDULE_TIME'] = 2020-04-01 13:31:00 EST
scheduleTime = datetime.strptime(r['SCHEDULE_TIME'],'%Y-%m-%d %H:%M:%S %Z')

编辑: 这与在 python 3.7 中执行 python 3.6 版本脚本有关。我需要它在 3.6 中运行,有没有办法做到这一点?

【问题讨论】:

    标签: python datetime strptime


    【解决方案1】:

    对于以后遇到这种情况的人,我的解决方案是在创建带有时间戳的日期时间后,将时区从时间戳中提取出来,并直接使用 replace(tzinfo=timezone_string_from_timestamp) 设置日期时间的 tzinfo 属性。

    【讨论】:

      猜你喜欢
      • 2020-02-28
      • 2015-06-18
      • 2018-01-29
      • 1970-01-01
      • 2020-08-17
      • 2020-07-24
      • 2014-11-12
      • 1970-01-01
      • 2020-06-28
      相关资源
      最近更新 更多