标准时间格式("%Y-%m-%dT%H:%M:%S")转化(基于python 3.6)

import json
import os
import datetime
import time
import linecache


#10分钟风速时间格式转化
def ws_time_format(JDtime,times,hour_time,minute_time):
JDtime = JDtime + minute_time * 600
dt = times + 'T'+ hour_time
time_array = datetime.datetime.strptime(dt, '%Y%m%dT%H:%M:%S')
timestamp = time.mktime(time_array.timetuple())
stime = float(JDtime) + timestamp
dt_new = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(float(stime)))
return dt_new

#最大风速、极大风速时间格式转化
def ws_max_time(max_time,create_time):
_time = []
for i in max_time:
_time.append(i)
Time = _time[0]+_time[1] + ':' +_time[2]+_time[3]+':00'
Hour = _time[0]+_time[1]
HOUR = int(Hour)
if 20<=HOUR and HOUR<=24:
dt = create_time + 'T' + Time
time_array = datetime.datetime.strptime(dt, '%Y%m%dT%H:%M:%S')
timestamp = time.mktime(time_array.timetuple())
dt_new = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(float(timestamp)))
return dt_new
else:
JDtime = 86400 #秒数
dt = create_time + 'T' + Time
time_array = datetime.datetime.strptime(dt, '%Y%m%dT%H:%M:%S')
timestamp = time.mktime(time_array.timetuple())
stime = float(JDtime) + timestamp
dt_new = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(float(stime)))
return dt_new
# print(_time)

#时间格式转化
def time_format(JDtime,times,start_time):
JDtime = JDtime #传入秒数
dt = times + 'T'+ start_time #times是类似于‘20180101’格式,starttime是‘20:00:00’格式
time_array = datetime.datetime.strptime(dt, '%Y%m%dT%H:%M:%S') #dt须与%Y%m%dT%H:%M:%S格式相同,这里运用了datetime.datetime.strptime()的接口
timestamp = time.mktime(time_array.timetuple())
stime = float(JDtime) + timestamp
dt_new = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(float(stime))) #本地时间格式同化
return dt_new

转载于:https://www.cnblogs.com/setname/p/8676497.html

你可能感兴趣的:(标准时间格式("%Y-%m-%dT%H:%M:%S")转化(基于python 3.6))