python time, datetime, string 之间转换

搜了一堆缺了time转datetime,这里放上代码:

time -> datetime

datetime.fromtimestamp(time.time())

别把time转换为localtime

datetime -> time

time.mktime(dateTim.timetuple())

time -> string

str = time.strftime("%Y-%m-%d %H:%M:%S",fileModifyTime)

string -> time

time.mktime(time.strptime(st, "%Y-%m-%d %H:%M:%S"))

datetime -> string

datetime.strftime("%Y-%m-%d %H:%M:%S")

string -> datetime

datetime.strptime(str,"%Y-%m-%d %H:%M:%S")

你可能感兴趣的:(python time, datetime, string 之间转换)