python - 将时间戳(纳秒格式)转换为日期时间
问题描述
我有一个纳秒格式的时间戳,我想将其转换为日期时间,但出现错误
import datetime
example_timestamp= '1629617204525776950'
example_timestamp= int(example_timestamp)
timestamp_to_date_time = datetime.datetime.fromtimestamp(example_timestamp).strftime('%Y-%m-%d %H:%M:%S,%f')
解决方案
您应该使用=
分配值而不是:
你可以这样做。
import datetime
example_timestamp = int('1629617204525776950')
timestamp_to_date_time = datetime.datetime.fromtimestamp(example_timestamp/1000000000).strftime('%Y-%m-%d %H:%M:%S,%f')
print(timestamp_to_date_time)
2021-08-22 07:26:44,525777
推荐阅读
- opencv - 在 gentoo 上的 libpng/png.h 上编译 opencv 失败
- tensorflow - GradientDescentOptimizer.minimize() 是如何工作的?
- javascript - 画线 JavaScript - 点击问题
- bash - ~/.ssh/known_hosts:没有这样的文件或目录 - 命令路径中的变量用法
- python - 在python中计算重复的JSON键
- angular - 如何使用 Nativescript 更改菜单中的颜色文本
- sql-server - 插入触发器后导致表锁定
- c++ - 移动语义+对成员成员变量的引用 - 解决方案和命名法?
- go - 是否可以在不同的文件范围内重用常量名称?
- javascript - 与js文件冲突