?
Solved

How,in Java, do I obtain NTP time from one of the US time servers (us.pool.ntp.org)?

Posted on 2015-02-13
8
Medium Priority
?
339 Views
Last Modified: 2015-03-03
I need to obtain time from an ntp server in my Java program.

How do I do that?

Thanks,


Chris
0
Comment
Question by:Christopher Schene
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 36

Assisted Solution

by:mccarl
mccarl earned 800 total points
ID: 40609288
There is nothing builtin to Java to do this, so you would manually have to create and send the right request packets and then decode the response... or you can use a library like Apache Commons Net (http://commons.apache.org/proper/commons-net/)

The page linked to above has downloads for the library (or details for getting via Maven if you use it) and also in the main info of the page is a link to an example for doing exactly what you are after. Have a go with all that and if there are any problems let us know.
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 40610084
There are examples for to query a NTP server for the time around on the net, I've seen one on stackoverflow.com, written in C#. Shouldn't be that much complicated to port to Java.

Just search for "query NTP server socket" on Google. Sorry for not posting the code itself, but I don't want to publish other people's code under my name.
0
 

Author Comment

by:Christopher Schene
ID: 40610506
Thanks for your advice.

With respect I pay for EE membership precisely because I generally do not wish to do the leg work of finding answers to my Java language question,  I am sure I will eventually be able to figure this out on my own if I've no other choice but I would rather something close to an answer. I can probably translate .net or c++ answers to Java.


I will look at the common library and see if there is something there I can use, but if I figure out the answer I split credit between the expert and myself with me getting most of the points.
0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 36

Expert Comment

by:mccarl
ID: 40610697
Also with respect, I can't download the library for you and if you are after code that is a bit more specific to your situation than the example, then you would actually have had to give us more details about your situation.

If you were after a solution that didn't involve using a 3rd party library, then it maybe a good idea to state that in your initial question, or at least in a comment prior to making threats of splitting points, etc.
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 40610972
With respect, too, I did most of the legwork for you ... I just don't want to put another man's feathers on my hat. I've found a nice and short example code in C#, and I pointed you right the way to it ...
0
 

Accepted Solution

by:
Christopher Schene earned 0 total points
ID: 40615819
I found this java example though I have not tried it yet.
blah.java
0
 
LVL 36

Expert Comment

by:mccarl
ID: 40615823
That is exactly what I was referring to in my initial comment, ie. that is the example off the Apache Commons Net page and to use it requires downloading the library.
0
 

Author Closing Comment

by:Christopher Schene
ID: 40641311
I did most of the work: I found the example on the net. the other experts made suggestions and provided a link.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question