将年/月/日添加到UNIX时间戳中,在python中仅使用小时/分钟/秒

问题描述 投票:0回答:1

我的时间戳范围从34200到57600,因此它涵盖从上午9:30开始的一天的一部分。我想在此时间戳中添加特定的年/月/日。我怎么能在python中做到这一点?假设我的时间戳是34201.054427731004。我想要一个时间戳,其中包含有关年/月/日的信息(例如,3/2/2017)作为输出。所以在这里,UNIX输出是一个完整的时间戳,而不仅仅是小时/平均值/秒。

python timestamp unix-timestamp
1个回答
2
投票

使用日期创建一个datetime对象,该日期将小时和分钟初始化为0,并添加timedelta及其秒数:

from datetime import datetime, timedelta

date = datetime(2017, 2, 3) + timedelta(seconds=34201)
print(date.timestamp())
© www.soinside.com 2019 - 2024. All rights reserved.