如何在java中使用EPOCH时间?
我必须发送一条带有系统当前时间(历元)的消息,该消息将根据以下细节发送。同时,以纳秒为单位发送新纪元时间如何在java中使用EPOCH时间?,java,integer,epoch,Java,Integer,Epoch,我必须发送一条带有系统当前时间(历元)的消息,该消息将根据以下细节发送。同时,以纳秒为单位发送新纪元时间 field - current_time type - UINT64 byte size - 8 value - 0 to 1.84467E+19 我的消息结构如下: class MsgHeader { int message_length; String sender_sys; String destination_sys; **int current_time;
field - current_time
type - UINT64
byte size - 8
value - 0 to 1.84467E+19
我的消息结构如下:
class MsgHeader {
int message_length;
String sender_sys;
String destination_sys;
**int current_time;**
char message_type;
................
}
有谁能建议我如何使用java实现这一点吗?我将当前时间的长值转换为字节,如下所示
long current_time = System.currentTimeMillis() * 1000000L;
public static byte[] longToBytes(long current_time) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(Long.SIZE / 8);
DataOutputStream dos = new DataOutputStream(baos);
dos.writeLong(current_time);
byte[] result = baos.toByteArray();
dos.close();
System.out.println(result.length);//length=8bytes
return result;
}
实际上支持搜索也是如此。我想发送8字节的当前时间范围,并根据给定的规格。你确定要纳秒,而不是毫秒吗?谢谢,这非常有用