0
如何將帶時區信息的時間字符串轉換爲ISO格式字符串?將帶時區信息的時間字符串轉換爲ISO格式
如:
時間字符串時區信息
time = "2012-01-01T10:30:00-05:00"
ISO格式的時間字符串
time = "2012-01-01T15:30:00Z"
如何將帶時區信息的時間字符串轉換爲ISO格式字符串?將帶時區信息的時間字符串轉換爲ISO格式
如:
時間字符串時區信息
time = "2012-01-01T10:30:00-05:00"
ISO格式的時間字符串
time = "2012-01-01T15:30:00Z"
def timestamp(time):
form dateutil import parser
time = parser.parse(time) #Converts string in to datetime object
from pytz import UTC
if time.tzinfo: #Checks if the time is aware or naive
time = time.astimezone(UTC) #Converts aware time into UTC
return time.strftime('%Y%m%dT%H%M%SZ')
的可能重複[如何解析與-0400時區字符串中的日期蟒?](http://stackoverflow.com/questions/1101508/how-to-parse-dates-with-0400-timezone-string-in-python) –