2013-05-30 5 views
0

표준 시간대 정보가있는 시간 문자열을 iso 형식 문자열로 변환하는 방법은 무엇입니까?시간대 정보가있는 시간 문자열을 iso 형식으로 변환

예 :

시간대 정보와

시간 문자열

time = "2012-01-01T10:30:00-05:00" 

ISO 형식의 시간 문자열

time = "2012-01-01T15:30:00Z" 
+0

의 중복 가능성 [-0400 시간대 문자열과 날짜를 구문 분석하는 방법 python?] (http://stackoverflow.com/questions/1101508/how-to-parse-dates-with-0400-timezone-string-in-python) –

답변

0
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') 
관련 문제