Here I have string like this "1322485986.672901000", data type is string which represents unixtime. I want to convert it into datetime in Python.
The way I used is date = datetime.fromtimestamp(float(row[0])) row[0] represents value like this 1322485986.672901000, since I have several rows. The convert result is wrong, it only calculates the digits before the dot. So the date after conversion is like 2011-11-28 13:53:23.6729
I think the problem is float(row[0]), but I don’t know how to solve this problem, or does anyone know how to convert unixtime to datetime in a better way?
Many thanks!
Now the result I got is 2011-11-28 14:13:06.672901
But when using an online converter, the result is 2011-11-28 13:13:06
Your one-hour difference in the current result is likely the consequence of time zone application.
You can supply an explicit time zone if you need to — the docs on tzinfo objects can steer you straight on creating your time zone object, and once it’s created, you just pass in the argument:
This code prints 2011-11-28 13:13:06.672901+00:00 for me.