Grabbing the Date and Time From a Time Server on the Internet

Peter M. Brigham, MD pmbrig at gmail.com
Sat Aug 13 17:03:05 EDT 2011


On Aug 13, 2011, at 1:33 PM, Gregory Lypny wrote:

> Taking another kick at the cat here.  I’d like to use something like
> 
> 	get url (http://[time server address])
> 
> to grab the current date and time from an official time server.  This would be used in a LiveCode standalone distributed to collaborators and grad students who would use it to export time-sensitive data.  I want the data to be date- and time-stamped, and I cannot count on their computer clocks being accurate.
> 
> I suppose an alternative would be to get the creation date and time of the file once it is received via FTP (or better still, SFTP) use the the server date and time as the standard.
> 
> Anyone?  Please?

I sent this message a couple days ago, apparently it never went through. (Parenthetically, even though I've set my preferences on the use-Livecode mailing list webpage to "Receive your own posts to the list" = "yes", I never see any of my own postings.)

------------------

You can fetch the time from the U.S. Naval Observatory atomic clock. This assumes an internet connection, though. In my little stack, the time zone is chosen by the user, so I fetch it from a customprop. You'll have to calculate the time offset from the last word of the internet date on the user machine -- I'll leave that to you. You need to convert something like "-0400" [EDT] to "1", "-0500" to "2" etc. but in winter the internet date will return "-0500" for eastern *standard* time so you'll have to correct for that. The object is to get the correct line of the HTMLtext of the tycho webpage. Check out the format of the page, it's simple HTMLtext.

This will give you a start:

function fetchTime
 put URL "http://tycho.usno.navy.mil/cgi-bin/timer.pl" into t
 -- gives a list of current times for all US time zones
 put the timeZone of stack "TimeHelp" into h
 -- time zone is as follows
 -- daylight time is given if currently applicable
 -- 1 = eastern
 -- 2 = central
 -- 3 = mountain
 -- 4 = pacific
 -- 5 = alaska
 -- 6 = hawaii
 put line 6+h of t into tTime
 delete item 1 of tTime
 return tTime
end fetchTime

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig





More information about the Use-livecode mailing list