Python - time difference in milliseconds not working for me

前端 未结 5 2100
野性不改
野性不改 2020-12-05 22:51

I\'ve read a few posts about this and thought I had some code that worked. If the difference between the 2 values is less than a 1sec then the millisecs displayed is correct

5条回答
  •  抹茶落季
    2020-12-05 23:38

    The correct answer (in 2020) is:

    >>> from datetime import timedelta
    >>> timedelta(days=1, milliseconds=50) / timedelta(milliseconds=1)
    86400050.0
    

    The other answers lose precision and/or are more verbose.

提交回复
热议问题