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()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章