64 位无符号到 32 位有符号
我需要将 Java long 数据类型(64 位)数据转换为旧版 c++ 应用程序 unsigned int(32 位)数据类型。
不用担心数据丢失,因为数据是 Linux 时间戳,这需要很长时间才能达到 unsigned int 限制。
知道对这些数字应用什么转换吗?
提前致谢!
PS - 数据类型示例:
Java - 1266336527340
C++ - 1266336583
它们都产生相同的日期和大约相同的时间(+/-一分钟)。
I need to convert Java long datatype (64-bit) data into legacy c++ app unsigned int (32-bit) datatype.
No worries about the data loss as the data is Linux timestamp, which would take aeons to hit unsigned int limit.
Any idea what transformation to apply to these numbers?
Thanks in advance!
P.S. - data-types example:
Java - 1266336527340
C++ - 1266336583
They both produce same date, and about same time (+/- a minute).
Java 的 Date.getTime 返回距纪元的毫秒数,而 C++ 代码期望距纪元的秒数,因此您需要除以 1000 然后截断:
Java 只有有符号整数而不是无符号整数,但这应该可以工作。
Java's Date.getTime returns the number of milliseconds from the epoch, whereas the C++ code expects the number of seconds from the epoch, so you need to divide by 1000 then truncate:
Java has only a signed integer not unsigned, but this should work.