时间格式有“TZ“标准时间转换用Python转换(2020-12-01T03:21:57.330Z)

T表示分隔符,Z表示的是UTC。
UTC:世界标准时间,在标准时间上加上8小时,即东八区时间,也就是北京时间

import datetime
import time
def get_time_stamp(result):
    utct_date1 = datetime.datetime.strptime(result, "%Y-%m-%dT%H:%M:%S.%f%z")#2020-12-01 03:21:57.330000+00:00
    utct_date2 = time.strptime(result, "%Y-%m-%dT%H:%M:%S.%f%z")#time.struct_time(tm_year=2020, tm_mon=12, tm_mday=1, tm_hour=3, tm_min=21, tm_sec=57, tm_wday=1, tm_yday=336, tm_isdst=-1)
    print(utct_date1)
    print(utct_date2)
    local_date = utct_date1 + datetime.timedelta(hours=8)#加上时区
    local_date_srt = datetime.datetime.strftime(local_date,"%Y-%m-%d %H:%M:%S.%f")#2020-12-01 11:21:57.330000
    print(local_date_srt)
    time_array1 = time.mktime(time.strptime(local_date_srt,"%Y-%m-%d %H:%M:%S.%f"))#1606792917.0
    time_array2 = int(time.mktime(utct_date2))#1606764117
    print(time_array1)
    print(time_array2)

    #js方法
    # created_time = new Date(result).getTime()

if __name__ == '__main__':
    get_time_stamp("2020-12-01T03:21:57.330Z")

你可能感兴趣的:(python,python)