B4J Question Read the real time from any web service

desof

Well-Known Member
Licensed User
Longtime User
Hello,

as I can read from the actual date B4j from some web service?
me or is this line returns the system date

B4X:
 DateActual = DateTime.Date(DateTime.Now)

But the same could be impaired and need the real time ...

B4X:
DateActual = date from www ...... ?


It is possible ?
 

dilettante

Active Member
Licensed User
Longtime User
If the jNet library was extended to supported Apache Commons Net NTP classes then something like this would be possible:

How do I query the NIST Internet Time Service using the Network Time Protocol?

Or perhaps it would be possible for somebody to create a separate NTP wrapper based on that Java library. I'm too new at Java and B4J to undertake this myself at this time.

The result would be far lighter in weight than an HTTP web service. NIST doesn't like the high cost of supporting any TCP-based protocol, let alone something as expensive as a web service.

http://tf.nist.gov/tf-cgi/servers.cgi/en-en/
We will continue to support the "TIME" protocol that uses tcp port 37 for the forseeable future. However, this protocol is very expensive in terms of network bandwidth, since it uses the complete tcp machinery to transmit only 32 bits of data. Users are *strongly* encouraged to upgrade to the network time protocol (NTP), which is both more accurate and more robust.
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
Actually it's a bit complex.
And if I add a record to my database just before .. and then there is a way to check from the BD to the same time I add?
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
ENJOY!!!!


Finally I solved myself looking a little here and a little there

We must create a php being called from code by Job.

Excuse my bad English since I use google translator



B4X:
ExecuteRemoteQuery(" ",List)

Sub ExecuteRemoteQuery1(Query As String, JobName As String)
    Dim job As HttpJob

    job.Initialize(JobName, Me)
    job.PostString("http://www.xxxxxx.com/date.php", "")
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success Then
    Dim res As String
    Dim tmpNum As String
    Dim TMP As String
   
        res = Job.GetString 'GetGetString'("UTF8")
        Dim parser As JSONParser
        parser.Initialize(res)
   
        Select Job.JobName

                Case List
                    lbDateActual.Text = Job.GetString
'   
        End Select
   
    Else
        'ToastMessageShow("Error: " & Job.ErrorMessage, True) 
    End If
    Job.Release
End Sub

PHP:
<?php

// Hora en Buenos Aires (Argentina)
putenv('TZ=America/Argentina/Buenos_Aires');
$hora_argentina = date("H:i:s");

// Segundos transcurridos desde el 01-01-1970
$utc = time();

// Una forma de expresar la fecha
$fecha1 = date("d-m-Y H:i");


echo "
$fecha1
";
?>

Fuentes de aqui >>> http://www.uterra.com/codigo_php/codigo_php.php?ref=fecha_y_hora_con_php

un ejemplo >>> http://www.uterra.com/archcodfuente/demos/id78/fecha_hora.php
 
Upvote 0
Top