Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 python 新手。我需要将时间戳转换2012-06-15T05:31:55Z为秒。
2012-06-15T05:31:55Z
我怎样才能做到这一点?
您正在尝试从该字符串中获取 unix 时间戳(即,自纪元以来的秒数),对吗?
然后基本上是这样的:
timeStr = "2012-06-15T05:31:55Z" timestamp = time.mktime( time.strptime( timeStr, "%Y-%m-%dT%H:%M:%SZ" ) ) print timestamp >>> 1339756315.0
但是,您确实需要注意时区信息。此代码转换为本地时间。您可能还想转换为 GMT 或其他格式。