標準時間フォーマット("%Y-%m-%dT%H:%M:%S")変換(python 3.6ベース)

2269 ワード

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