Convert python datetime to timestamp in milliseconds

前端 未结 5 683
你的背包
你的背包 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:45

    You need to parse your time format using strptime.

    >>> import time
    >>> from datetime import datetime
    >>> ts, ms = '20.12.2016 09:38:42,76'.split(',')
    >>> ts
    '20.12.2016 09:38:42'
    >>> ms
    '76'
    >>> dt = datetime.strptime(ts, '%d.%m.%Y %H:%M:%S')
    >>> time.mktime(dt.timetuple())*1000 + int(ms)*10
    1482223122760.0
    

提交回复
热议问题