将列表从纪元时间转换为人类可读时间
Convert list from epoch to human readable time
大家早上好,
我在 Python 中有一个列表,其中包含一些纪元时间。我想以人类可读的时间转换每个纪元时间。我通常会使用此代码,但我不知道如何在列表中使用它:
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1483947846/1000.0))
我在 Python 中的列表是:
myList = [ '1483947846', '1417947246', '1417327000']
非常感谢!
定义函数:
def epoch2human(epoch):
return time.strftime('%Y-%m-%d %H:%M:%S',
time.localtime(int(epoch)/1000.0))
或lambda
epoch2human = lambda epoch: time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(epoch)/1000.0))
并使用这样的东西:
humanTimes = [epoch2human(t) for t in myList]
大家早上好, 我在 Python 中有一个列表,其中包含一些纪元时间。我想以人类可读的时间转换每个纪元时间。我通常会使用此代码,但我不知道如何在列表中使用它:
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1483947846/1000.0))
我在 Python 中的列表是:
myList = [ '1483947846', '1417947246', '1417327000']
非常感谢!
定义函数:
def epoch2human(epoch):
return time.strftime('%Y-%m-%d %H:%M:%S',
time.localtime(int(epoch)/1000.0))
或lambda
epoch2human = lambda epoch: time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(epoch)/1000.0))
并使用这样的东西:
humanTimes = [epoch2human(t) for t in myList]