2024-10-04 01:27:28 发布
网友
我试图在python中将epoch datetime转换为字节数组 但它是10字节的,应该是4字节的。在
from time import time curTime = int(time.time()) b = bytearray(str(curTime)) len(b) #comming as 10
我错了谁能帮忙吗
您正在转换时间戳的字符串表示形式,而不是整数。在
您需要的是这个函数:
在结构打包成(fmt,缓冲器,偏移量,v1,v2,…) 它记录在顶部附近的http://docs.python.org/library/struct.html。在
import struct from time import time curTime = int(time()) b = struct.pack(">i", curTime) len(b) # 4
从这里偷来的: https://stackoverflow.com/a/7921876/2442434
您正在转换时间戳的字符串表示形式,而不是整数。在
您需要的是这个函数:
在结构打包成(fmt,缓冲器,偏移量,v1,v2,…) 它记录在顶部附近的http://docs.python.org/library/struct.html。在
从这里偷来的: https://stackoverflow.com/a/7921876/2442434
相关问题 更多 >
编程相关推荐