From 5ff47bd71a15a947b215ed8509321e7b18568514 Mon Sep 17 00:00:00 2001 From: "bb3600@student.uni-lj.si" Date: Fri, 23 Jan 2015 16:48:52 +0000 Subject: git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@227 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- kpov_judge/tasks/custom_rdate/CustomRDate.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 kpov_judge/tasks/custom_rdate/CustomRDate.java 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 -- cgit v1.2.1