我试图读取以小端二进制文件编写的(.SKD)文件。我确实打开了文件并选择/打印了代表时间戳的4个字节,我有兴趣将其转换为HH形式:MM
我拥有的字节示例: 26,231,215,85 148,20,216,85 90,253,215,85
答案 0 :(得分:1)
试试这个:
import struct
import datetime
def convert(timestamp):
return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
def binary_to_int(b):
return struct.unpack('<i', b)[0] # read string as little endian integer
sampledata = [26, 231, 215, 85]
binarydata = struct.pack('<BBBB', *sampledata)
timestamp = binary_to_int(binarydata)
result = convert(timestamp)
struct模块用于将二进制文件读取为小端