summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kpov_judge/tasks/custom_rdate/CustomRDate.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/kpov_judge/tasks/custom_rdate/CustomRDate.java b/kpov_judge/tasks/custom_rdate/CustomRDate.java
new file mode 100644
index 0000000..426dece
--- /dev/null
+++ b/kpov_judge/tasks/custom_rdate/CustomRDate.java
@@ -0,0 +1,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.");
+ }
+ }
+} \ No newline at end of file