The Python time function learns a whole lot, so how do you convert a Greenwich time string to local time?
Here is an example of how to convert a GMT string to Beijing time.
GMT String: 2015-08-31t11:20:48
First, convert the string to a tuple format that represents time:
>>> t=time.strptime (' 2015-08-31t11:20:48 ', '%y-%m-%dt%h:%m:%s ') >>> ttime.struct_time (tm_year= Tm_mon=8, tm_mday=31, tm_hour=11, tm_min=20, tm_sec=48, tm_wday=0, tm_yday=243, Tm_isdst=-1)
At this point, the string can be represented in the touple format. That's OK if we add 8 to the hour number and then we can read the log format. But in Python, a tuple is not able to be changed (the concept is a little blurry, it should be).
That's the only way to do it.
>>> i=list (t) >>> i[2015, 8, 0, 243, -1]>>> i[3] = i[3] + 8>>> i[2015, 8, 31, 19, 20, 48, 0, 243,-1]
At this point, the difference is how to express to everyone can read the format.
>>> time.strftime ('%y-%m-%d%h:%m:%s ', tuple (i)) ' 2015-08-31 19:20:48 '
In this way, it should be in line with our expectations. Oh! It's so nerve-racking!
This article is from the "RIP Notes" blog, please make sure to keep this source http://unixman.blog.51cto.com/10163040/1694035
How to convert a Greenwich string time format to local time