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
267 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 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: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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

777 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