python datetime milliseconds

from datetime import datetime

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

Here is what the above code is Doing:
1. datetime.utcnow() gives us the current time in UTC.
2. strftime(‘%Y-%m-%d %H:%M:%S.%f’)[:-3] formats the current time in UTC to the format we want.
3. The [:-3] at the end removes the trailing milliseconds from the string.