2013-11-05 92 views
0

上午9点unix时间戳如果我想知道系统的第二天上午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 

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

回答

2

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

+0

如果当前时间是上午11点,然后添加datetime.timedelta(小时= 24)会给我第二天11 AM – jdk2588

+0

@ jdk2588的时间,但随后设置时间值将使第二天的上午9点这正是什么你问了。 –

+0

是啊!正确的感谢 – jdk2588