UTC格式转换成本地时间
澳门威尼斯人官网
澳门威尼斯人官网
当前位置 : 澳门威尼斯人官网 > 澳门威尼斯人官网

UTC格式转换成本地时间

txt文件格式如下:
area time data
1 1383260400000 11.02836638168102645352
1 1383261000000 11.12710087567367445160
1 1383261600000 10.89277060279109754504
1 1383262200000 8.62242459098974833864
1 1383262800000 8.00992746244575570813
1 1383263400000 8.11841955408960025409
1 1383264000000 8.02626974851215102547
1 1383264600000 8.51417857718389292643
······
其中area的值从1到10000,time的值为UTC格式的时间,data为需要的数据
现在想把time的时间改为本地时间,我Python新手一个,尝试写了一个程序,如下:

#!user/bin/env python3
# -*- coding: gbk -*-
import time
file = openday00.txt, a+
file.close
file = openday0.txt,r
line = file.readline
time1 = []  #时间
data1 = []  #data
area = []

while 1:
    line = file.readline
    if line == :
        break
    a = line.split
    if a[0]==area:
        break
    if inta[0] == 1:
        area.appenda[0]
        time1.appenda[1]
        data1.appenda[2]
    elif inta[0] < 10001:
        if a[0] not in area:
            area.appenda[0]
            file1 = openday00.txt, a+

            for i in time1:
                l_time = time.localtimeinti/1000
                #ltime=time.localtime1479285300
                timeStr=time.strftime"%Y-%m-%d %H:%M:%S", l_time
                file1.write"%-8s%-16s%.20f\n" % area[area.indexa[0]-1], timeStr, floatdata1[time1.indexi]
            file1.close
            file1 = openday00.txt, r
            file1.close
            time1 = []
            data1 = []

        else:
            time1.appenda[1]
            data1.appenda[2]
    else:
        break
file.close

file = openday00.txt, a+
for j in time1:
    l_time=time.localtimeinti/1000
    #ltime=time.localtime1479285300
    timeStr=time.strftime"%Y-%m-%d %H:%M:%S", l_time
    file.write"%-8s%-16s%.20f\n" % a[0], timeStr, floatdata1[time1.indexj]
file.close
# file = openday00.txt, r
# file.close

代码能跑通了
在一位大神的帮助下已经解决啦,谢谢~

学会看报错啊兄弟。这里说 area 无法转成 int,你就该想到应该先把第一行表头排除掉。

1
回复 zhengqh

不要边读边写,最好写到另一个文件

hsfzxjy · 4月11日

展开评论

广告位

澳门威尼斯人官网