将时间间隔转换为整数

3
我想把时间差转换成整数以便进行数学运算,但我一直收到以下错误提示:
numpy.core._exceptions._UFuncBinaryResolutionError: ufunc 'true_divide' cannot use operands with types dtype('O') and dtype('<m8[D]')

这里是代码:

zeit = datetime(2023, 1, 1)
    today = datetime.now()

    new_date = zeit-today

days_int=(new_date / np.timedelta64(1, 'D')).astype(int)

对于总时间使用 new_date.total_seconds(),如果您只想要 int 类型的天数,则使用 new_date.days - Anurag Dabas
如果你是在此之后,new_date.days 应该给你总天数。 - Selcuk
1个回答

2

如果您只想将日期转换为整数,则可以使用 new_date.days


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接