Questions About LiveCode Apps That Connect to the Internet

Peter M. Brigham, MD pmbrig at gmail.com
Wed Aug 10 15:14:42 EDT 2011


> How can I get the current date and time from either a time server or my remote Mac?  I need to timestamp student submissions and want the time coming from one source, not their own machines.

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