0

I am working on licensing and I need to get the current date and time from time server, that is irrespective of the time and date of the system.

I have tried Joda Time API and some classes of Java like TimeZone and I have seen that the value which I get is actually based on the system current time and date.

I have managed to get the TimeZone of the client machine to which it is set and now I want to query the time server for the current time of that TimeZone which will be not dependent on the system current date and time.

Will be helpful if I get some suggestions!

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
Arijit
  • 15
  • 4
  • "Will be helpful if I get some working code." - That's not how SO works ... – Fildor Aug 22 '16 at 11:01
  • Tell us what you have done so far... – Sheetal Mohan Sharma Aug 22 '16 at 11:01
  • 2
    May be [this can help you](http://stackoverflow.com/questions/4442192/how-to-use-an-internet-time-server-to-get-the-time) – Sanjeev Aug 22 '16 at 11:01
  • Here is one from another question. Never used it myself. http://stackoverflow.com/a/19962190/4418511 – GC_ Aug 22 '16 at 11:02
  • Changed my mind, now I think @Sanjeev 's link is better. Here is the answer from the question he linked, that I particularly liked. http://stackoverflow.com/a/13547204/4418511 – GC_ Aug 22 '16 at 11:06
  • My link was probably good for clientside stuff, though. His is exactly what you need. – GC_ Aug 22 '16 at 11:07
  • Are you worried about people faking a system time by changing the system clock? – GC_ Aug 22 '16 at 11:10
  • I have tried the solutions that are present in the question with which my present questions has been marked duplicate with, the solutions return time of the system clock or get modified when the system clock is changed. – Arijit Aug 23 '16 at 05:33
  • @GC_ Yes, that is what I am worrying about. I want to get the current time directly from the time server which won't get modified in any way when people change the system clock. – Arijit Aug 23 '16 at 05:33
  • Also, you could even use SSL, if you really want to give yourself and the hackers a headache. – GC_ Aug 23 '16 at 16:03
  • Did you check the answer I linked it, in the question @Sanjeev linked? I think that should not be your server time. – GC_ Aug 23 '16 at 16:06
  • @GC_ Yes I have tried that before posting this question here, that code does gives the time from some server but when I change the system time of my computer, the result of the program (fetched time from the server) changes too. – Arijit Sep 01 '16 at 12:19

1 Answers1

0

You can use TIMEAPI available here.


Alternatively, you can do some web-scraping.
www.time.is/GMT will give you current GMT time.
You can easily scrape the page with JSOUP or some other library.
FYI, the time is displayed within the element with the id of twd and the date is displayed within the element with the id dd.

CodeWalker
  • 2,281
  • 4
  • 23
  • 50
  • 4
    It is very dangerous to use web-scraping . because if the web page format is changed then we end up with trouble. It is better idea to use API exposed by some standard time servers . – JavaUser Aug 22 '16 at 13:03