Python 带有 time() 的时间戳
Python timestamps with time()
我在数据库中有几个时间戳,我想 trim 减少到大约 10 个时间戳,从最新到最旧。数据库中的所有时间戳都是使用 python 中的 time() 创建的。
创建时间戳:
_timestamp = time.time()
时间戳:
1435652632.92778
1435652633.01
1435652633.07
1435652633.13
1435652642.71371
1435652642.77
1435652675.13
1435652675.22
1435652717.74
1435652735.11
1435652735.16
1435652735.24
如何要求 python 删除最早的时间戳?
我目前在脚本中使用以下字符串将时间戳转换为可读格式。
print datetime.datetime.fromtimestamp(1434615010.27858)
>>2015-06-18 08:10:10.278580
我还没有删除最旧时间戳的代码,但是请提供一些帮助,我将不胜感激。
这是一个纪元时间戳,它只是自 1970-01-01T00:00:00Z 以来经过的秒数。
在你的例子中,对时间图进行排序并取前 10 个元素。
timestmaps = [1435652632.92778, 1435652633.01, 1435652633.07]
timestmaps.sort(reverse=True)
latestTimestamps = timestmaps[:10]
不确定这是否是您想要的,但您可以这样做:
timestamps = [1435652632.92778,1435652633.01,1435652633.07,1435652633.13,1435652642.71371,1435652642.77,1435652675.13,1435652675.22,1435652717.74,1435652735.11,1435652735.16,1435652735.24]
timestamps.remove(min(timestamps)) #Remove the minimum value from the list
我在数据库中有几个时间戳,我想 trim 减少到大约 10 个时间戳,从最新到最旧。数据库中的所有时间戳都是使用 python 中的 time() 创建的。
创建时间戳:
_timestamp = time.time()
时间戳:
1435652632.92778
1435652633.01
1435652633.07
1435652633.13
1435652642.71371
1435652642.77
1435652675.13
1435652675.22
1435652717.74
1435652735.11
1435652735.16
1435652735.24
如何要求 python 删除最早的时间戳?
我目前在脚本中使用以下字符串将时间戳转换为可读格式。
print datetime.datetime.fromtimestamp(1434615010.27858)
>>2015-06-18 08:10:10.278580
我还没有删除最旧时间戳的代码,但是请提供一些帮助,我将不胜感激。
这是一个纪元时间戳,它只是自 1970-01-01T00:00:00Z 以来经过的秒数。
在你的例子中,对时间图进行排序并取前 10 个元素。
timestmaps = [1435652632.92778, 1435652633.01, 1435652633.07]
timestmaps.sort(reverse=True)
latestTimestamps = timestmaps[:10]
不确定这是否是您想要的,但您可以这样做:
timestamps = [1435652632.92778,1435652633.01,1435652633.07,1435652633.13,1435652642.71371,1435652642.77,1435652675.13,1435652675.22,1435652717.74,1435652735.11,1435652735.16,1435652735.24]
timestamps.remove(min(timestamps)) #Remove the minimum value from the list