将数字转化成时间格式
from dateutil.parser import parse a=20170825 b=str(a) c=parse(b)
print(c)
2017-08-25 00:00:00
将时间按照天排列,转化为一个数字,用来做时间序列分析
from matplotlib.pylab import date2num e = date2num(c) e Out[30]: 736566.0
将时间转化为时间戳
d=str(c) d Out[25]: '2017-08-25 00:00:00'
from matplotlib.pylab import date2num timeArray = time.strptime(d,"%Y-%m-%d %H:%M:%S") timeArray Out[27]: time.struct_time(tm_year=2017,tm_mon=8,tm_mday=25,tm_hour=0,tm_min=0,tm_sec=0,tm_wday=4,tm_yday=237,tm_isdst=-1) timestamp = time.mktime(timeArray) timestamp Out[29]: 1503590400.0原文链接:https://www.f2er.com/python/526703.html