Python3 - 时间戳转日期

import pymongo
import time
from bson.int64 import long

# 输入 - 文件
inPath = 'D:/projectData/EcSystem/Amazon/ratings.csv'
inFile = open(inPath, 'r', encoding='UTF-8')

for line in inFile:
    # 去掉末尾换行符
    line = line.strip('\n')
    arr = line.split(',')
    try:
        time01 = time.localtime(long(arr[3]))
        time02 = time.strftime("%Y-%m-%d", time01)
        print(time02)
    except:
        print(line)

inFile.close()

你可能感兴趣的:(Python3)