How to format time and convert to gmt time?

2019-06-10 18:52发布

I have a date string in the format of 3/29/2010. Can someone tell me how to convert it to GMT time?

标签: python time
2条回答
做自己的国王
2楼-- · 2019-06-10 19:41

This very suspiciously appears that you are trying to correct something for daylight savings time, which is not really something you should be doing manually.

You should review the datetime documentation, and specifically the portions related to using time zones.

查看更多
小情绪 Triste *
3楼-- · 2019-06-10 19:47
if (timeH,timeM)>(2,0): # if it is after 2 am
    timeH1=timeH+5
    if timeH1>=24:#deduct 24 hrs whenever it's over 24
        timeH1=timeH1-24
else:
    timeH1=timeH+4

could be changed to: timeH1 = (timeH + 5) % 24

and you also need to check the other case and subtract 24 which you aren't doing now

查看更多
登录 后发表回答