zoukankan      html  css  js  c++  java
  • 标准时间格式("%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
  • 相关阅读:
    Eclipse中插件的运用
    AES加密解密 Java中运用
    DES加密解密 Java中运用
    Chrome中的插件运用
    JqueryEasyUI教程入门篇
    SEO入门教程
    屏幕取色工具
    gif处理
    java 实现序列化的两种方式
    重定向输出 > 1>&2 2>&1
  • 原文地址:https://www.cnblogs.com/setname/p/8676497.html
Copyright © 2011-2022 走看看