python - 有没有办法计算秒的 32 位小数?
问题描述
我正在尝试获取 64 位(8 字节)的 python 十六进制时间戳(当前时间/一天中的时间)。
new0 = hex(int(time.time()))[2:]
new0
'60cc8697' <--- (only 32 bits of MSB bits)
预期格式(秒的分数):(32 位 LSB 位)60cc839600000000
试过:使用python版本:python3.8
new0 = hex(long(time.time())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'long' is not defined
解决方案
您不需要使用字符串,只需一个位掩码。
>>> hex(int(time.time()) & 0xffffffff000000000)
'0x0'
但是,2038 年之前的时间戳不会设置任何高 32 位。也许您想要高 48 位(即实际使用的 32 位的高 16 位):
>>> hex(int(time.time()) & 0xffffffffffff0000)
'0x60cc0000'
或者(出于某种原因)您可能只想用 32 位 0 填充时间戳。你可以用左移来做到这一点。
>>> hex(int(time.time()) << 32)
'0x60cc8e4200000000'
推荐阅读
- angular - 保存 GET 响应的 Angular,ngrx 问题,带有嵌套数组,用于存储
- mysql - 两次加入同一个表时,Sum 返回错误的值
- dll - 使用 MinGW gfortran 编译时在 Windows 上无法识别 DLL
- kotlin - Visual Studio Code 中 Kotlin 的 ArrayIndexOutOfBoundsException
- apache-nifi - NiFi:用于分组的 ParitionRecord 处理器
- r - 在悬停模板中添加自定义数据(情节,闪亮,r)
- html - 从 Dart 的 html 正文中获取值
- calibration - 多类分类的校准预测
- python-3.x - 如何将输入(TextCtrl)存储到变量中,通过一些代码行处理它并在 wxPython 的另一个窗口中显示输出?
- amazon-web-services - DynamoDB 更新是否具有强一致性?