Amigos,
quizá es algo tonto pero no puedo encontrar la respuesta.
Como hago para obtener la fecha y la hora de Internet?
Muchas gracias...
Roberto
// Internet time
#include "FiveWin.ch"
function Main()
LOCAL cGetHora, cFecha, cHora, hFecha, wDia, wMes, wAno, wFecha
// MsgInfo( GetNtpDate( "204.123.2.72" ) )
cGetHora := GetNtpDate( "204.123.2.72" )
cHora := SUBST( cGetHora, 11, 9 )
? "hora.: ", cHora
WDIA := SUBST( cGetHora, 1, 3 )
? CDOW( DATE() )
WMES := SUBST( cGetHora, 4, 4 )
? CMONTH( DATE() )
WANO := SUBST( cGetHora, 20, 5 )
? YEAR( DATE() )
WFECHA := WDIA +"/"+ WMES +"/"+ WANO
? WFECHA
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <winsock.h>
#include <time.h>
#define MAXLEN 1024
HB_FUNC( GETNTPDATE )
{
char * hostname = ( char * ) hb_parc( 1 );
unsigned char msg[ 48 ] = { 010, 0, 0, 0, 0, 0, 0, 0, 0 }; // the packet we send
unsigned long buf[ MAXLEN ]; // the buffer we get back
struct sockaddr_in server_addr;
int s; // socket
WSADATA wsa;
struct timeval timeout;
fd_set fds;
time_t tmit;
WSAStartup( 0x101, &wsa );
s = socket( PF_INET, SOCK_DGRAM, getprotobyname( "udp" )->p_proto );
memset( &server_addr, 0, sizeof( server_addr ) );
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = inet_addr( hostname );
server_addr.sin_port = htons( 123 ); // ntp port
sendto( s, msg, sizeof( msg ), 0, ( struct sockaddr * ) &server_addr, sizeof( server_addr ) );
FD_ZERO( &fds );
FD_SET( s, &fds );
timeout.tv_sec = 10;
timeout.tv_usec = 0;
if( select( 0, &fds, NULL, NULL, &timeout ) )
{
recv( s, ( void * ) buf, sizeof( buf ), 0 );
tmit = ntohl( buf[ 10 ] );
tmit-= 2208988800U;
}
else
MessageBox( 0, "can't read", "ok", 0 );
WSACleanup();
hb_retc( ctime( &tmit ) );
}
#pragma ENDDUMP
oHttp:Open("GET","http://www.horacerta.com.br/index.php?city=sao_paulo",.f.)
aHrDt := HrDtInternet()
IF .NOT. ISINTERNET()
dDataBra := "SEM NET"
ELSE
dDataBra := CTOD( aHrDt[1] )
ENDIF
Function HrDtInternet()
Local oHttp, ;
cResp1 := "", ;
cResp := "", ;
cHora := "", ;
cData := ""
local _oTmr
DEFINE TIMER _oTmr ;
INTERVAL 1000 ;
ACTION SysRefresh()
ACTIVATE TIMER _oTmr
IF !IsInternet()
_oTmr:End()
Return( {DtoC(Date()), Time()} )
ENDIF
Try
oHttp := CreateObject("winhttp.winhttprequest.5.1")
oHttp:Open("GET","http://www.horacerta.com.br/index.php?city=sao_paulo",.f.)
oHttp:Send()
cResp1 := oHttp:ResponseText()
Catch
_oTmr:End()
Return( {DtoC(Date()), Time()} )
End Try
*<input name="mostrador" type="text" size="25" value="19/09/2011 - 01:02:00 PM" />
cResp := SubStr( cResp1 , At( '<input name="mostrador"', cResp1 ) )
cResp := Substr( cResp , 1, At( '/>', cResp )-2 )
cDados := SubStr( cResp , At( 'value="', cResp )+7 )
cData := SubStr( cDados, 1, 10)
cHora := SubStr( cDados, 14 )
/*
If "PM" $ cHora
cHora := Str(Val(SubStr(cHora,1,2))+12,2)+SubStr(cHora,3,7)
End
*/
If "PM" $ cHora .AND. SubStr(cHora,1,2) != "12"
cHora := Str(Val(SubStr(cHora,1,2))+12,2)+SubStr(cHora,3,7)
Endif
wDIA := VAL(SUBSTR( cData, 1, 2 ) )
wMES := VAL(SUBSTR( cData, 4, 2 ) )
wANO := VAL(SUBSTR( cData, 7, 4 ) )
wHOR := VAL(SUBSTR( cHora, 1, 2 ) )
wMIN := VAL(SUBSTR( cHora, 4, 2 ) )
wSEG := VAL(SUBSTR( cHora, 7, 2 ) )
_oTmr:End()
* MsgInfo("Data: "+cData+CRLF+"Hora: "+cHora,"Na internet")
Return( {cData, cHora} )
TOTOVIOTTI wrote:Joao
Eso es lo que necesitaba!
Gracias!
Roberto
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot], VictorCasajuana and 47 guests