pythonpython-arrow

Python Arrow milliseconds


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


Solution

  • 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