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
246 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:cschene
  • 3
  • 3
  • 2
8 Comments
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 200 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 13

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:cschene
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
 
LVL 35

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 13

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:
cschene earned 0 total points
ID: 40615819
I found this java example though I have not tried it yet.
blah.java
0
 
LVL 35

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:cschene
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now