python timestamp milliseconds code example

Example 1: python datetime milliseconds

from datetime import datetime

print(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])

Example 2: python datetime milliseconds

from datetime import datetime

dt_obj = datetime.strptime('20.12.2016 09:38:42,76',
                           '%d.%m.%Y %H:%M:%S,%f')
millisec = dt_obj.timestamp() * 1000

print(millisec)

Example 3: timestamp to date time till milliseconds python

from datetime import datetime

print datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]

>>>> OUTPUT >>>>
2020-05-04 10:18:32.926