Java and time

alocurto

Platinum Member
Nov 4, 1999
2,174
0
76
I have an application that needs to have the current time, this is important. Right now I am using government time servers, tokenizing the string and updating the time object I created to reflect the time. I am running into trouble with daylight savings time and timezones. I can totally write the code to do it manually and all that but is there a reliable time server running a script that I can pass some params and get the proper time? Would save me some work. I have been to time.gov but can't find dull documentation on their timezone.cgi script.

basically I would like to hit:

time.gov/timezone.cgi?Eastern

and get the current time. Have all the daylight savings and all that stuff done server side and just get the current time, ya know?
 

Softballslug

Senior member
Feb 22, 2000
397
0
0
Although I don't know for certain, there should be some kind of web service available that you could request the time from
 

alocurto

Platinum Member
Nov 4, 1999
2,174
0
76
hmmm... Soapy. That could be cool, anyone have any more info on that? It doesn't even have to be a webservice. I just need to hit the page and grab the string of time. I can tokenize it no problem.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
In the past I had used the NIST Time Servers using NTP to synchronize with the local time based on an offset from the UTC time. You can use NTP or the DayTime protocol, both of which are easily usable with simple sockets code. Using the DayTime protocol I simply took the response from the time server and parsed it with a regular expression. e.g. response from their server:

52890 03-09-08 18:15:29 50 0 0 361.6 UTC(NIST) *

And the regular expression:

\w{5}\s(?<date>(?<year>\w{2})-(?<month>\w{2})-(?<day>\w{2}))\s(?<time>(?<hour>\w{2}):(?<minute>\w{2}):(?<second>\w{2}))

I used it in C#. There's more info on their site, but I believe this would be the best means of accomplishing your goals.
 

alocurto

Platinum Member
Nov 4, 1999
2,174
0
76
I have been doing it that way. The problem with that is I get the wrong time for my time zone (EST) and I have to adjust it manually before I put it into my date object. I would really like to ask the server the current time in a specfic timezone and get that with out doing calculations.