问题描述
是否有可能具有存储为每个元素为64位双Mac的绝对时间二进制或十六进制数值数组转换?
当我使用点var_bytes
控制台显示下面的输出检查数组中。
Is it possible to convert Array having binary or hex values stored as each element into 64bit Double Mac Absolute Time?When I inspect array using p var_bytes
console shows following output.
\000\000\000\000\000\000\000\000\000\000\000\234\225x\266A\000\000\000\345\005\230\264
是否有可能在64位双Mac的绝对时间以上的数组元素转换为字符串?
Is it possible to convert above array elements in 64bit Double Mac Absolute Time as a string?
我的code只是遵循一个简单的 do..end
My code is following just a simple do..end
puts "\nClose off the page header#{y.unpack("n")}\n"
z.scan(/(.{8})(.{8})(.{4})(.{4})(.{4})(.{4})(.{8})(.{8})(.{8})(.*\w)/m).each do |j,k,l,m,n,o,p,q,r,s|
puts "\nContent1#{j.unpack("n")}\n"
puts "\nContent2:#{k.unpack("n")}\n"
puts "\nContent3:#{l.unpack("n")}\n"
puts "\nContent4:#{m.unpack("n")}\n"
puts "\nContent5:#{n.unpack("n")}\n"
puts "\nContent6:#{o.unpack("n")}\n"
puts "\nContent7:#{p.unpack("n")}\n"
expdt = Time.at((q.unpack("L"))[0])
createdt = Time.at((r.unpack("L"))[0])
puts "Date1:\n#{expdt}\n"
puts "\nDate2:\n#{createdt}\n"
puts "\nCookie:\n"
puts s.split(/\0/m)
end
end
会出现什么简单的方法来此负值转变为积极如此Time.at根据MAC大纪元时间不会给错误,然后将其转换?
what will the simple way to convert this negative values to positive so Time.at wont give error and then convert it according to MAC Epoch time?
推荐答案
试试这个:
MAC_EPOCH = Time.gm(2001,1,1)
def bin2time(bin)
return MAC_EPOCH + (bin.unpack "D")[0]
end
其中,斌
是一个双precision浮动的8字节再presentation。
where bin
is an 8-byte representation of a double precision float.
您可能需要根据你在哪里得到您的数据改变D到E或G。
查看文档的详细信息。
you may need to change "D" to "E" or "G" depending on where you are getting your data from.check the unpack
docs for details.
这篇关于如何使用Ruby数组转换成64位双Mac的绝对时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!