Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中使用EPOCH时间?_Java_Integer_Epoch - Fatal编程技术网

如何在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字节的当前时间范围,并根据给定的规格。你确定要纳秒,而不是毫秒吗?谢谢,这非常有用