I am trying to figure out one simple thing - how to convert arrow.Arrow
object into milliseconds. I was reading following thread but it still not clear to me how to get a long number in milliseconds.
I want something like:
def get_millis(time: arrow.Arrow):
... some magic goes here ...
print(get_millis(time))
OUTPUT:
1518129553227
Thanks
strptime() function in python converts the string into DateTime objects. The strptime() is a class method that takes two arguments : string that should be converted to datetime object.
Arrow is a Python module for working with date and time. It offers a sensible and human-friendly approach to creating, manipulating, formatting and converting dates, times and timestamps. It allows easy creation of date and time instances with timezone awareness.
This is an inelegant answer: from your linked question, you can get the milliseconds as a string and then add them to the timestamp:
import arrow
now = arrow.utcnow()
s = now.timestamp
ms = int(now.format("SSS"))
print(s * 1000 + ms)
Which prints:
1518131043594
Essentially the property you're looking for is
float_timestamp
E.g.
now_millisecs = round(arrow.utcnow().float_timestamp, 3)
now_microsecs = round(arrow.utcnow().float_timestamp, 6)
if you don't like the floating point, you can take it from here with:
str(now_millisecs).replace('.', '')
I personally leave the floating point representation for both visual convenience and ease of calculations (comparisons etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With