标签:
import datetime print datetime.datetime.now() # 2016-03-28 17:16:00.812000 a = ‘2016-03-28 17:16:00.812000’ timeArray = time.strptime(a, ‘%Y-%m-%d %H:%M:%S.%f‘) ##注意: %f是microseconds的格式化符号。 print timeArray #time.struct_time(tm_year=2016, tm_mon=3, tm_mday=28, tm_hour=17, tm_min=22, tm_sec=38, tm_wday=0, tm_yday=88, tm_isdst=-1)
a = datetime.datetime.now() print a ## a变量不指向一个字符串对象,而是指向一个datetime.datetime类型的对象 # 2016-03-28 17:24:52.571000 timeArray = time.strptime(a, ‘%Y-%m-%d %H:%M:%S.%f‘) ## 所有这里报错。 time.striptime的第一个参数,应该是字符串对象 Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Python27\lib\_strptime.py", line 467, in _strptime_time return _strptime(data_string, format)[0] File "C:\Python27\lib\_strptime.py", line 322, in _strptime found = format_regex.match(data_string) TypeError: expected string or buffer
datetime.datetime.now()时间格式转化是碰到的问题
标签:
原文地址:http://www.cnblogs.com/haoshine/p/5329862.html