How to convert local time string to UTC?

后端 未结 23 1171
离开以前
离开以前 2020-11-22 04:18

How do I convert a datetime string in local time to a string in UTC time?

I\'m sure I\'ve done this before, but can\'t find it and SO will hopefull

23条回答
  •  无人及你
    2020-11-22 04:48

    How about -

    time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(seconds))
    

    if seconds is None then it converts the local time to UTC time else converts the passed in time to UTC.

提交回复
热议问题