>How can I get the current date and time from the internet and can I specify
>a time zone? Is there a windows API call or what do I need?
Below is code I have on hand... Hopefully it will get you started.
atomictime.prg
LOCAL cTimeServer1 as String,cTimeServer2 as String,cDateTimeSuffix as
String,cTimeSuffix as String,;
cTimeZone as string, cGMTOffset as String,mDate as String, mTime as
string,dtDatetime as Datetime
cTimeServer1 = "129.6.15.28" && "tick.usno.navy.mil" &&"129.6.15.28"
cTimeServer2 = "216.200.93.8"
cDateTimeSuffix = "13" && Port used to obtain Network Time Protocol (RFC-1305)
RETURN value is a string
*!* This protocol is widely used by small computers running MS-DOS and similar
operating
*!* systems. The server listens on *!* port 13, and responds to requests in
either tcp/ip or
*!* udp/ip formats. The standard does not specify an exact format for *!* the
Daytime Protocol,
*!* but requires that the time is sent using standard ASCII characters. NIST
chose a time code
*!* format *!* similar to the one used by its dial-up Automated Computer Time
Service (ACTS),
*!* as shown below:
*!* JJJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) OTM
*!* where:
*!* JJJJJ is the Modified Julian Date (MJD). The MJD has a starting point of
midnight on
*!* November 17, 1858.
*!* You can obtain the MJD by subtracting exactly 2 400 000.5 days from the
Julian Date,
*!* which is an integer day number obtained by counting days from the starting
*!* point of noon on 1 January 4713 B.C. (Julian Day zero).
*!* YR-MO-DA is the date. It shows the last two digits of the year, the month,
and the current
*!* day of month.
*!* HH:MM:SS is the time in hours, minutes, and seconds. The time is always sent
as Coordinated
*!* Universal Time (UTC).
*!* An offset needs to be applied to UTC to obtain local time. For example,
*!* Mountain Time in the U. S. is 7 hours behind UTC during Standard Time, and 6
hours
*!* behind UTC during Daylight Saving Time.
*!* TT is a two digit code (00 to 99) that indicates whether the United States
is on
*!* Standard Time (ST) or Daylight Saving Time (DST). It also indicates when ST
or DST
*!* is approaching.
*!* This code is set to 00 when ST is in effect, or to 50 when DST is in effect.
*!* During the month in which the time change actually occurs, this number will
*!* decrement every day until the change occurs. For example, during the month
of
*!* October, the U.S. changes from DST to ST. On October 1, the number will
change
*!* from 50 to the actual number of days until the time change. It will
decrement by
*!* 1 every day until the change occurs at 2 a.m. local time when the value is
1.
*!* Likewise, the spring change is at 2 a.m. local time when the value reaches
51.
*!* L is a one-digit code that indicates whether a leap second will be added or
subtracted at
*!* midnight on the last day of the current month. If the code is 0,
*!* no leap second will occur this month.
*!* If the code is 1, a positive leap second will be added at the end of the
month.
*!* This means that the last minute of the month will contain 61 seconds instead
of 60.
*!* If the code is 2, a second will be deleted on the last day of the month.
*!* Leap seconds occur at a rate of about one per year. They are used to correct
for
*!* irregularity in
*!* the earth's rotation. The correction is made just before midnight UTC (not
local
*!* time).
*!* H is a health digit that indicates the health of the server. If H=0, the
server is healthly.
*!* If H=1, then the server is operating properly but its time may be in error
by up to
*!* 5 seconds.
*!* This state should change to fully healthy within 10 minutes. If H=2, then
the
*!* server is operating properly but its
*!* time is known to be wrong by more than 5 seconds. If H=4, then a hardware or
*!* software failure has occurred and
*!* the amount of the time error is unknown.
*!* msADV displays the number of milliseconds that NIST advances the time code
to partially
*!* compensate for network delays.
*!* The advance is currently set to 50.0 milliseconds.
*!* The label UTC(NIST) is contained in every time code. It indicates that you
are receiving
*!* Coordinated Universal Time (UTC)
*!* from the National Institute of Standards and Technology (NIST).
*!* OTM (on-time marker) is an asterisk (*). The time values sent by the time
code refer to the
*!* arrival time of the OTM.
*!* In other words, if the time code says it is 12:45:45, this means it is
12:45:45 when the
*!* OTM arrives.
cTimeSuffix = "37" && Port used to obtain Time Protocol (RFC-868)
*!* This simple protocol is now used by only about 1% of ITS customers. It
returns a 32-bit
*!* unformatted binary number that represents
*!* the time in UTC seconds since January 1, 1900. The server listens for Time
Protocol
*!* requests on port 37,
*!* and responds in either tcp/ip or udp/ip formats. Conversion to local time
(if
*!* necessary) is the responsibility of the client program.
*!* The 32-bit binary format can represent times over a span of about 136 years
with a
*!* resolution of 1 second.
*!* There is no provision for increasing the resolution or increasing the range
of
*!* years.
*!* The strength of the time protocol is its simplicity. Since many computers
keep time
*!* internally as the number of seconds since
*!* January 1, 1970 (or another date), converting the received time to the
necessary
*!* format is often a simple matter of
*!* binary arithmetic. However, the format does not allow any additional
information to
*!* be transmitted,
*!* such as advance notification of leap seconds or daylight saving time, or
*!* information about the health of the server.
*!* Please see http://tf.nist.gov/service/its.htm for full explanation
CLEAR
DECLARE INTEGER GetTimeZoneInformation IN kernel32 STRING @lpTimeZoneInformation
#DEFINE TIME_ZONE_SIZE 172
cTimeZone = Repli(Chr(0), TIME_ZONE_SIZE)
GetTimeZoneInformation(@cTimeZone)
cGMTOffset = buf2dword(SUBSTR(cTimeZone, 1,4)) && in minutes
? cGMTOffset/60 && hours. Minus values are ahead of GMT
loIE = CREATEOBJECT('InternetExplorer.Application')
&& Navigate to the datetime server info at 129.6.15.28:13
loIE.Navigate("http://"+cTimeServer1+":"+cDateTimeSuffix)
IF WaitForReadyState(loIE)
mResponse = loIE.Document.Body.InnerHTML
? "RAW time",mResponse
&& calculate local date and time
mDate = SUBSTR(mResponse,7,8)
mTime = SUBSTR(mResponse,16,8)
? "Date/time" mDate,mTime
dtDateTime = CTOT(SUBSTR(mResponse,7,17))
? "time value",dtDateTime
? "adjusted/local",dtDatetime - cGMTOffset * 60
? "Local Time :" + TTOC(dtDatetime - cGMTOffset * 60 )&& convert the
offset to seconds
ELSE
MESSAGEBOX("Unable to connect to the Time Server",16,;
"Internet Connection Down")
ENDIF
&& function and declaration courtesy of news2news.com. Thanks Anatoliy
FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
BitLShift(Asc(SUBSTR(lcBuffer, 2,1)), 8) +;
BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
FUNCTION WaitForReadyState(oBrowser,lnReadyState, lnMilliSeconds)
LOCAL lnX
IF EMPTY(lnReadyState)
lnReadyState = 4
ENDIF
IF EMPTY(lnMilliSeconds)
lnMilliSeconds = 4000
ENDIF
lnX = 0
DO WHILE oBrowser.ReadyState != lnReadyState AND lnX < lnMilliSeconds
DOEVENTS
lnX = lnX + 1
Sleep(1)
ENDDO
IF lnX < lnMilliSeconds
RETURN .T. && Not timed out
ENDIF
RETURN .F.
ENDFUNC
gettimezone.prg
FUNCTION GetTimeZone
LPARAMETERS pcfunc
lctzinfo = num2dword(0)+REPLICATE(CHR(0), 64)+REPLICATE(num2word(0),
8)+num2dword(0)+REPLICATE(CHR(0), 64)+REPLICATE(num2word(0), 8)+num2dword(0)
DECLARE INTEGER GetTimeZoneInformation IN kernel32.dll STRING @
lcres = gettimezoneinformation(@lctzinfo)
lnbias = buf2dword(lctzinfo)
lcdesc = "Unknown"
DO CASE
CASE lcres=1
lcdesc = SUBSTR(lctzinfo, 3, 64)
lcdesc = STRCONV(lcdesc, 6)
lcdesc = STRTRAN(lcdesc, CHR(0), '')
CASE lcres=2
lcdesc = SUBSTR(lctzinfo, 3, 64)
lcdesc = STRCONV(lcdesc, 6)
lcdesc = STRTRAN(lcdesc, CHR(0), '')
ENDCASE
IF VARTYPE(pcfunc)='C' .AND. pcfunc='NAME'
RETURN lcdesc
ENDIF
RETURN lnbias
ENDFUNC
FUNCTION num2dword
LPARAMETERS lnvalue
LOCAL b0, b1, b2, b3
b3 = INT(lnvalue/16777216)
b2 = INT((lnvalue-b3*16777216)/65536)
b1 = INT((lnvalue-b3*16777216-b2*65536)/256)
b0 = MOD(lnvalue, 256)
RETURN CHR(b0)+CHR(b1)+CHR(b2)+CHR(b3)
ENDFUNC
FUNCTION num2word
LPARAMETERS lnvalue
RETURN CHR(MOD(m.lnvalue, 256))+CHR(INT(m.lnvalue/256))
ENDFUNC
FUNCTION buf2word
LPARAMETERS lcbuffer
RETURN ASC(SUBSTR(lcbuffer, 1, 1))+ASC(SUBSTR(lcbuffer, 2, 1))*256
ENDFUNC
FUNCTION buf2dword
LPARAMETERS lcbuffer
RETURN ASC(SUBSTR(lcbuffer, 1, 1))+ASC(SUBSTR(lcbuffer, 2,
1))*256+ASC(SUBSTR(lcbuffer, 3, 1))*65536+ASC(SUBSTR(lcbuffer, 4, 1))*16777216
ENDFUNC
MikeA napsal(a):
> How can I get the current date and time from the internet and can I specify
> a time zone? Is there a windows API call or what do I need?
>
> Thanks,
> Mike
oie=createobject("InternetExplorer.Application")
oie.Navigate("http://tycho.usno.navy.mil/cgi-bin/timer.pl")
do while oie.ReadyState <> 4
doevents
enddo
cTime = oie.Document.Body.InnerText
oie.Quit()
cTime = substr(cTime, at(',', cTime) + 2)
cTime = substr(cTime, 1, at(chr(13), cTime) - 1)
cTime = alltrim(strtran(cTime, 'UTC', ''))
? cTime + ' - this is UTC time'
MikeA - 08 Aug 2007 22:30 GMT
Thanks - that's exactly what I was looking for.
Mike
> MikeA napsal(a):
>> How can I get the current date and time from the internet and can I
[quoted text clipped - 15 lines]
> cTime = alltrim(strtran(cTime, 'UTC', ''))
> ? cTime + ' - this is UTC time'
MikeA - 08 Aug 2007 23:11 GMT
I spoke to soon. That website is not giving the year. I need everything -
date and time.
Thanks,
Mike
> Thanks - that's exactly what I was looking for.
>
[quoted text clipped - 19 lines]
>> cTime = alltrim(strtran(cTime, 'UTC', ''))
>> ? cTime + ' - this is UTC time'
MikeA - 09 Aug 2007 00:25 GMT
Found another site that works for me and includes the year:
loExplorer.Navigate("http://nist.time.gov/timezone.cgi?Pacific/d/-8")
Thanks for the ideas.
Mike
>I spoke to soon. That website is not giving the year. I need everything -
>date and time.
[quoted text clipped - 25 lines]
>>> cTime = alltrim(strtran(cTime, 'UTC', ''))
>>> ? cTime + ' - this is UTC time'
Josh Assing - 09 Aug 2007 02:03 GMT
source code didn't work for you eh?
I got into a lot of problems using the iexplorer once when they changed the
object so that it responded differently...
>Found another site that works for me and includes the year:
>
[quoted text clipped - 33 lines]
>>>> cTime = alltrim(strtran(cTime, 'UTC', ''))
>>>> ? cTime + ' - this is UTC time'
Fred Taylor - 09 Aug 2007 02:35 GMT
You're missing the DECLARE for Sleep.

Signature
Fred
Microsoft Visual FoxPro MVP
> source code didn't work for you eh?
>
[quoted text clipped - 40 lines]
>>>>> cTime = alltrim(strtran(cTime, 'UTC', ''))
>>>>> ? cTime + ' - this is UTC time'
Josh Assing - 09 Aug 2007 06:14 GMT
>You're missing the DECLARE for Sleep.
I may be -- but if that's all that's wrong with it......
I was just curious.
thanks fred.
-josh
Fred Taylor - 09 Aug 2007 16:15 GMT
>>You're missing the DECLARE for Sleep.
>
> I may be -- but if that's all that's wrong with it......
> I was just curious.
> thanks fred.
> -josh
Yep, that's all, it seems to work fine otherwise.

Signature
Fred
Microsoft Visual FoxPro MVP
MikeA - 10 Aug 2007 06:39 GMT
oie=createobject("InternetExplorer.Application")
is creating havoc on Vista (I think home edition on a friend's computer).
What is the story with Vista - it seems to be such a security problem. Am I
wrong or is one going to have to click a button on their computer to go to
the bathroom in the next version! Seriously speaking, I've encountered two
problems with users on Vista over the last week. It seems like just copying
files is a PITA and one has to allow permission even when they do the
copying and pasting even if they are an administrator. In VFP I cannot use
the COPY FILE command to copy to an exe program. I can't use StrToFile
either to create an exe program. For example: I can't do this COPY FILE
"test.txt" to "test.exe"
Is there some way to get past these Vista issues (perhaps its only with the
Vista home edition but I'm not sure yet). In fact, I learned that my
program can't register ActiveX controls either and they can't do it from the
start run and then have to go to the command prompt via a right click even
when they are already an administrator. Users are forced to go to Vista
with all these new computers. Any suggestions on all this?
Thanks,
Mike
>> On Wed, 8 Aug 2007 18:35:13 -0700, "Fred Taylor"
>> <ftaylor@mvps.org!REMOVE>
[quoted text clipped - 8 lines]
>
> Yep, that's all, it seems to work fine otherwise.
MikeA - 10 Aug 2007 07:02 GMT
To recap in short: how can I get these two commands to work on the Vista
Home edition because it appears the security won't allow them to work even
if the user is an administrator:
oie=createobject("InternetExplorer.Application")
and this one:
COPY FILE "test.txt" to "test.exe"
Thanks,
Mike
> oie=createobject("InternetExplorer.Application")
>
[quoted text clipped - 31 lines]
>>
>> Yep, that's all, it seems to work fine otherwise.