-1

does anyone has an idea on how to transform milliseconds to a datetime object? Here is my request:

ts = 1538589841191
from pymongo import MongoClient
client = MongoClient()
client = MongoClient('localhost', 27017)
db = client.local
collection = db.orderbook_update
orderbook = collection.find_one({
    "lastUpdated": ts
})

and my result of orderbook[u'lastUpdated'] = 1538589841191.0

Does someone have an idea on how to transform this float into a datetime object to end up with something like: datetime.datetime(2018, 10, 3, 16, 27, 29, 198000)

cs95
  • 379,657
  • 97
  • 704
  • 746
Viktor.w
  • 1,787
  • 2
  • 20
  • 46

1 Answers1

0

Here's what I would do:

from datetime import datetime
ms = 1538589841191.0
obj = datetime.fromtimestamp(ms/1000)  ## fromtimestamp accepts arguments in seconds
Rachit Bhargava
  • 170
  • 1
  • 12