在python中获取9am unix时间戳

时间:2013-11-05 05:50:55

标签: python datetime

如果我想知道系统第二天上午9点的时间戳,

可能有两种情况:

1. If the current time is 11 P.M of 2013-11-05 and I want to get the timestamp for 9 A.M 2013-11-06

2. If the current time is 2 A.M for 2013-11-06 and I need the timestamp for 9 A.M for same day

有没有更好的方法来处理这个或我分别计算我的小时,天,月,年,然后生成我想避免的日期时间对象。

1 个答案:

答案 0 :(得分:2)

这看起来很简单。检查时间;如果它小于09:00,那么只需用replace设置时间值。如果它更大,请添加datetime.timedelta(hours=24)并执行相同的操作。