blob: 426dece680d85e09a114c6fc20ae58b3a27a38f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import java.io.InputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.Date;
public class CustomRDate {
public static void main(String main[]) throws Exception{
try {
Socket s = new Socket("ntp1.arnes.si", 37);
InputStream vhod = s.getInputStream();
byte podatek[] = new byte[8];
int dejanskoPrebranih = vhod.read(podatek, 4, 4);
ByteBuffer buf = ByteBuffer.wrap(podatek);
long stevilka = buf.getLong() - 2208988800L;
Date d = new Date(stevilka*1000);
System.out.println(d);
} catch(Exception e) {
System.out.println("Nedosegljiv streznik.");
}
}
}
|