Search code examples
pythontimestamptimedelta

Convert timedelta to milliseconds python


I have the following time:

time = datetime.timedelta(days=1, hours=4, minutes=5, seconds=33, milliseconds=623)

Is it possible, to convert the time in milliseconds?
Like this:

101133623.0

Solution

  • I found a possibility to solve the problem

    import datetime
    
    time = datetime.timedelta(days=1, hours=4, minutes=5, seconds=33, milliseconds=623)
    result = time.total_seconds()*1000
    print(result)