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 questions, but didn't found this specific question/answer.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
For Python2.7
You can format it into seconds and then multiply by 1000 to convert to millisecond.
Output:
You need to parse your time format using strptime.
For Python2.7 - modifying MYGz's answer to not strip milliseconds:
Output:
In Python 3 this can be done in 2 steps:
datetime
objectdatetime
object by 1000 to convert it to milliseconds.For example like this:
Output:
strptime
accepts your timestring and a format string as input. The timestring (first argument) specifies what you actually want to convert to adatetime
object. The format string (second argument) specifies the actual format of the string that you have passed.Here is the explanation of the format specifiers from the official documentation:
%d
- Day of the month as a zero-padded decimal number.%m
- Month as a zero-padded decimal number.%Y
- Year with century as a decimal number%H
- Hour (24-hour clock) as a zero-padded decimal number.%M
- Minute as a zero-padded decimal number.%S
- Second as a zero-padded decimal number.%f
- Microsecond as a decimal number, zero-padded on the left.