Convert python datetime to timestamp in milliseconds

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

    For Python2.7

    You can format it into seconds and then multiply by 1000 to convert to millisecond.

    from datetime import datetime
    
    d = datetime.strptime("20.12.2016 09:38:42,76", "%d.%m.%Y %H:%M:%S,%f").strftime('%s')
    d_in_ms = int(d)*1000
    print(d_in_ms)
    
    print(datetime.fromtimestamp(float(d)))
    

    Output:

    1482206922000
    2016-12-20 09:38:42
    

提交回复
热议问题