Ubidots Community

[SOLVED] Convert timestamp on json

Hello can i convert timestamp data contained on json to default date in python? hh:mm:ss

Hi @alfendo

Here’s an example of how you can convert the timestamp returned by Ubidots to a human readable date.

from ubidots import ApiClient
from datetime import datetime

api = ApiClient(token="XXXXXXo7IKIZKAVSyTGqb1XXXXXXX")

variable = api.get_variable("578c230076254215XXXXXXX")

value = variable.get_values(1)[0]

timestamp = value.get("timestamp")

# Unix epoch format
print "Timestamp: {0}".format(timestamp)

# Human readable format
print "Human readable: {0}".format(datetime.fromtimestamp(timestamp / 1000).strftime("%H:%M:%S"))


1 Like