python 字符串变成时间格式方法

#String to Date(datetime)
def stringToDate(string): 
    #example '2013-07-22 09:44:15+00:00' 
    dt = datetime.strptime(string, "%Y-%m-%d %H:%M:%S+00:00") 
    #print dt 
    return dt 
#Date(datetime) to String   
def dateToString(date): 
    ds = date.strftime('%Y-%m-%d %H:%M:%S') 
    return ds 
#return n hours after datetime   
def getAfterDate(n): 
    dnow = datetime.datetime.now() 
    dafter = dnow + datetime.timedelta(hours=n) 
    #dafter.ctime() 
    return dafter 

你可能感兴趣的:(python)