Convert python datetime to timestamp in milliseconds

前端 未结 5 678
你的背包
你的背包 2020-12-05 04:18

How to convert a human readable time with the format 20.12.2016 09:38:42,76 to Unix timestamps in milliseconds? I found a lot of similar questi

5条回答
  •  遥遥无期
    2020-12-05 04:44

    For those who searches for an answer without parsing and loosing milliseconds, given dt_obj is a datetime:

    python3 only, elegant

    int(dt_obj.timestamp() * 1000)
    

    both python2 and python3 compatible:

    import time
    
    int(time.mktime(dt_obj.utctimetuple()) * 1000 + dt_obj.microsecond / 1000)
    

提交回复
热议问题