python中通过日期转换函数把字符串格式的日期转换成datetime格式的日期格式
time.strptime() converts the string to a struct_time tuple.
time.mktime() converts this tuple into seconds (elasped since epoch, C-style).
datetime.fromtimestamp() converts the seconds to a Python datetime object.
>>> import datetime,time >>> stringDate = "2006-05-18 19:35:00" >>> dt = datetime.datetime.fromtimestamp(time.mktime(time.strptime(stringDate,"%Y-%m-%d %H:%M:%S"))) >>> print dt 2006-05-18 19:35:00 >>> print type(dt) <type 'datetime.datetime'> >>>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8445.html