【问题标题】:Local Time To UTC time pytz本地时间到 UTC 时间 pytz
【发布时间】:2013-08-26 09:44:38
【问题描述】:

我在 pytz 的帮助下转换了 python 日期时间。

转化是这样的

2013-08-23T09:53:03 至 2013-08-23T15:23:03+05:30(时间已更改 根据时区)

现在的问题是“在另一个位置,我得到 time as string 2013-08-23T15:23:03+05:30 我如何将此字符串转换为 2013-08-23T09: 53:03

提前致谢

【问题讨论】:

    标签: python datetime python-2.7 pytz


    【解决方案1】:

    你可以使用非常有用的 dateutil 包

    from dateutil import parser
    import pytz
    UTC = pytz.timezone('UTC')
    date = parser.parse("2013-08-23T15:23:03+05:30")
    dateutc = date.astimezone(UTC)
    print dateutc.isoformat() 
    # or user strptime to have in the format you want (without time zone)
    print dateutc.strftime("%Y-%m-%dT%H:%M:%S")
    

    【讨论】:

      猜你喜欢
      • 2017-06-15
      • 2014-10-05
      • 2013-01-04
      • 2011-08-13
      • 2015-07-26
      • 2017-03-10
      • 2017-09-17
      • 2021-08-02
      • 2015-12-09
      相关资源
      最近更新 更多