How to convert local time string to UTC?

后端 未结 23 1597
离开以前
离开以前 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 05:08

    You can do it with:

    >>> from time import strftime, gmtime, localtime
    >>> strftime('%H:%M:%S', gmtime()) #UTC time
    >>> strftime('%H:%M:%S', localtime()) # localtime
    

提交回复
热议问题