2013-03-01 4 views
0

시스템의 현재 시간 (EPOCH)의 메시지를 보내야하며 다음 세부 정보에 따라 보내야합니다. 또한 EPOCH 시간은 나노초 단위로 전송됩니다. 내 메시지 구조는 다음과 같습니다자바에서 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;** 
    char message_type; 

................ 

} 

사람은 어떻게 사용하는 자바를 수행하는 날을 제안 해주십시오 수 있을까?

+0

실제로 검색을 지원합니다. – Drogba

+0

나는 8bytes의 현재 시간 범위를 주어진 스펙에 따라 보내고 싶었다. – pradeekrathnayaka

+0

_milliseconds_가 아닌 _nanoseconds_를 원하십니까? – jtahlborn

답변

2
long current_time = System.currentTimeMillis() * 1000000L; 
+0

감사합니다. 매우 도움이되었습니다. – pradeekrathnayaka

0

current_time의 long 값을 다음과 같이 바이트로 변환했습니다.

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; 
    } 
관련 문제