-1

I am playing around with my google location data (which one can download here https://takeout.google.com/settings/takeout).

The location data is a json file, of which one variable is 'timestaMps' (e.g. one observation is "1475146082971"). How do I convert this into a datetime?

Thanks!

Lysis90
  • 67
  • 9
  • Have you tried something like [this](http://stackoverflow.com/questions/3682748/converting-unix-timestamp-string-to-readable-date-in-python)? – lrnzcig Oct 08 '16 at 09:52

1 Answers1

0

Use fromtimestamp method from datetime module. To convert your 'timestaMps' to timestamp you need to convert it to int(). Formating of timestamp is done with strftime().

from datetime import datetime
datetime.fromtimestamp(int("1475146082971")).strftime('%Y-%m-%d %H:%M:%S')
Tuc3k
  • 1,032
  • 9
  • 12
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – andreas Oct 08 '16 at 10:24