赞
踩
import datetime
import pandas as pd
yyyyMMddHHmmss_begin = '20191201_000000'
yyyyMMddHHmmss_end = '20191211_000000'
yyyyMMddHHmmss_begin = datetime.datetime.strptime(yyyyMMddHHmmss_begin, '%Y%m%d_%H%M%S').strftime('%Y-%m-%d')
yyyyMMddHHmmss_end = (datetime.datetime.strptime(yyyyMMddHHmmss_end, '%Y%m%d_%H%M%S')+datetime.timedelta(days=1)).strftime('%Y-%m-%d')
# 每second_interval秒生成一次时间
Second_interval = 300
time_predict_iter = pd.date_range(start = yyyyMMddHHmmss_begin, end = yyyyMMddHHmmss_end, freq = str(Second_interval)+'s')
结果 time_predict_iter
time_predict_iter[0]的type是Timestamp
str1 = time_predict_iter[1].strftime("%Y-%m-%d %H:%M:%S")
dt = datetime.datetime.strptime(str1, "%Y-%m-%d %H:%M:%S")
获取dt的hour、minute、second
dt.hour
dt.minute
dt.second
str_time = time_predict_iter.strftime("%Y-%m-%d %H:%M:%S")
date_time = []
for i in range(len(str_time)):
date_time.append(datetime.datetime.strptime(str_time[i], "%Y-%m-%d %H:%M:%S"))
HH = []
mm = []
ss = []
for i in range(len(date_time)):
HH.append(date_time[i].hour)
mm.append(date_time[i].minute)
ss.append(date_time[i].second)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。