【问题标题】:Python: How to convert google location timestaMps in a year-month-day-hour-minute-seconds format?Python:如何将谷歌位置时间戳转换为年-月-日-时-分-秒格式?
【发布时间】:2016-10-08 09:46:17
【问题描述】:

我正在玩弄我的谷歌位置数据(可以在这里下载https://takeout.google.com/settings/takeout)。

位置数据是一个 json 文件,其中一个变量是“timestaMps”(例如,一个观察值是“1475146082971”)。如何将其转换为日期时间?

谢谢!

【问题讨论】:

  • 你试过类似this的东西吗?

标签: python google-maps datetime timestamp


【解决方案1】:

使用日期时间模块中的fromtimestamp 方法。 要将“timestaMps”转换为时间戳,您需要将其转换为 int()。时间戳的格式是用strftime() 完成的。

from datetime import datetime
datetime.fromtimestamp(int("1475146082971")).strftime('%Y-%m-%d %H:%M:%S')

【讨论】:

  • 虽然这段代码 sn-p 可以解决问题,including an explanation 确实有助于提高您的帖子质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
猜你喜欢
  • 1970-01-01
  • 2012-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多