【发布时间】:2018-07-17 05:25:36
【问题描述】:
我正在编写一个程序来打印两个时间范围(小时、分钟)之间的时间段范围(小时、分钟对)。我在运行时看到了意外的输出:
import datetime,time
def stamp(hour, min):
return int(datetime.datetime(2018, 7, 17, hour,min).timestamp())
def ListSlotsAvailable(start, ent, durn):
secdurn=durn*60
for sec in range(start, ent, secdurn):
enttime = sec+secdurn
print("Stamp is %d-%d" % (sec, enttime))
print(hour_from_stamp(sec))
print(min_from_stamp(sec))
print(hour_from_stamp(enttime))
print(min_from_stamp(enttime))
def hour_from_stamp(stamp):
import datetime
print(datetime.datetime.fromtimestamp(stamp).strftime('%H'))
def min_from_stamp(stamp):
import datetime
print(datetime.datetime.fromtimestamp(stamp).strftime('%M'))
starthr=input("Give start time in hour")
startmin=input("Give start time in min")
start=stamp(int(starthr), int(startmin))
endhr=input("Give end time in hour")
endmin=input("Give end time in min")
ent=stamp(int(endhr), int(endmin))
durn=int(input("Give duration for each consultation"))
ListSlotsAvailable(start, ent, durn)
输出:
Give start time in hour10
Give start time in min15
Give end time in hour12
Give end time in min30
Give duration for each consultation30
Stamp is 1531802700-1531804500
10
None
15
None
10
None
45
None
Stamp is 1531804500-1531806300
10
None
45
None
11
None
15
None
Stamp is 1531806300-1531808100
11
None
15
None
11
None
45
None
Stamp is 1531808100-1531809900
11
None
45
None
12
None
15
None
Stamp is 1531809900-1531811700
12
None
15
None
12
None
45
None
1
我没想到那里会看到 None 值。他们来自哪里?
【问题讨论】:
标签: python-3.x datetime time