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
317 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 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: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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 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