我需要创建一个具有年,月,日,小时,分钟,秒和百分之一秒的日期时间对象,保留第二个信息的分数。
可以这样做吗?
这失败了:
dto = dt.datetime(VLeaderData['Year'], month=VLeaderData['Month'],
day=VLeaderData['Day'],hour=VLeaderData['Hour'],
minute=VLeaderData['Minute'],
second=(VLeaderData['Second']+VLeaderData['Hundredths']/100))
因为第二个需要是一个整数: TypeError:期望的整数参数,浮点数
我是否已超出日期时间的功能?
答案 0 :(得分:2)
你只需要将所有内容都指定为整数......如果你将秒数作为浮点数:
seconds = 30.1234
然后取整数部分秒并计算微秒数:
secs = int(seconds)
microseconds = int((seconds - secs) * 100000)
或者,(如果我正确理解你的代码)你自己有百分之一秒作为一个字段:
microseconds = VLeaderData['Hundredths'] * 1000
然后将其全部传递给datetime
:
datetime.datetime(year, month, day, hour, minute, secs, microseconds)
答案 1 :(得分:1)
不,你没有。您可以将额外信息传递到datatime
对象的microsecond
参数:
microseconds = VLeaderData['Hundredths']*1000