Web Server Date-Time

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Web Server Date-Time

Post by andyglezl »

Hola

Habrá alguna forma de que al ejecutar mi programa.HMG, poder validar la fecha y hora contra un Servidor Web
( como los que muestra Windows ) para saber si la fecha del PC es la misma o en su defecto, sincronizarlo ?
Para evitar que se hagan movimientos con fecha diferentes a la del día actual o si la pila está fallando.
---------------------------------------------------------------------------------------------------------------------------------
Hey there

There will be some form of that running my programa.HMG, to validate the date and time against a Web Server
(As displayed in Windows) to see if the date of the PC is the same or alternatively, sync?
To prevent movements are made with different date to the current day or if the battery is failing.
ConfFecha.jpg
ConfFecha.jpg (57.61 KiB) Viewed 5978 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
gfilatov
Posts: 1074
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Web Server Date-Time

Post by gfilatov »

Hi Andrés González López,

There is the application Atomic Time with the similar features in the Minigui Ex distribution (since 2004).
Description
-----------
AtomicTime is a very simple time synchronizing program that retrieves the
accurate time from one of several specialized time servers on the Internet.
Once the network time has been retrieved the program can set your computer's
clock to match it.

Options in the program enable you to automatically obtain the time from the
time server and set your clock appropriately at program startup. It is also
possible to have the program automatically exit after the time has been set
and so is ideal for running a program at Windows Startup to sync your clock
when your computer is started.

AtomicTime uses the standard Time protocol (UDP port 37). See RFC 868 for
more details. The time retrieved from the network time server is given
as the number of seconds since midnight on January 1st 1900. Since the
protocol only allows accuracy down to the second you may not get the most
accurate time possible but it is usually good enough to always be within
about half a second of "true" time. Network latency is accommodated in the
calculations involved in setting your computer clock.


Usage
-----
Clicking the setup button ">>" shows you the program options. Clicking the
same button will hide the options.

The setup options allows you to choose the time server that is used by
selecting from a preset list in the dropdown list. You may prefer to use
one that is located nearer your computer for faster responses.

Select whether you want the program to automatically obtain and synchronize
to the network time when you start the program by clicking in the "Auto
sync at program startup" checkbox.

Select whether you want the program to exit after it has synced your clock
time by clicking in the "Exit after time has been synced" checkbox. If you
have this option set, the next time you start the program you can prevent
the program from exiting by de-selecting this same checkbox.


Disclaimer
----------
This product is supplied AS IS.
That means I support this product on my free will only. No upgrades, patches
or other stuff is provided on a regular basis.
I also bear no responsibilities for any damage to the software installed on
your PC caused by any actions when using this product.
It uses the TSocket Class by Matteo Baccan and works smoothly here 8-)
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Web Server Date-Time

Post by pctoledo »

Demo using Server NTP.
Attachments
demoMX.zip
(1.09 KiB) Downloaded 330 times
Regards/Saludos,

Toledo

Clipper On Line
User avatar
serge_girard
Posts: 3169
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Web Server Date-Time

Post by serge_girard »

Thanks Toledo !



Serge
There's nothing you can do that can't be done...
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Web Server Date-Time

Post by andyglezl »

Thanks Grigory
I will see this information
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Web Server Date-Time

Post by andyglezl »

Thanks Toledo
I'll prove it
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Web Server Date-Time

Post by andyglezl »

Hola Toledo

He estado intentando con el ejemplo que posteaste, pero no logro que me despliegue la fecha y la hora.
Probé con lo siguiente:

* cDataHora:= GetDataTimeNtp( "132.248.30.3") // "xalli.cie.unam.mx"
* cDataHora:= GetDataTimeNtp( "131.107.13.100") // "time.nist.gov"
cDataHora:= GetDataTimeNtp( "23.101.187.68") // "time.windows.com"
----------------------------------------------------------------------------------------------------
Hello Toledo

I've been trying with the example you posted, but I can not deploy my date and time.
I tried the following:

* cDataHora:= GetDataTimeNtp( "132.248.30.3") // "xalli.cie.unam.mx"
* cDataHora:= GetDataTimeNtp( "131.107.13.100") // "time.nist.gov"
cDataHora:= GetDataTimeNtp( "23.101.187.68") // "time.windows.com"

Siempre despliega: / Always displayed:
NTP Server.jpg
NTP Server.jpg (25.01 KiB) Viewed 5891 times
Algo que me falte hacer ? Alguien mas ya lo probó ?
----------------------------------------------------------------
I do miss something? But someone already tried?
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Web Server Date-Time

Post by andyglezl »

Encontré esto, pero no se como aplicarlo...
---------------------------------------------------------
I found this, but I do not know how to apply ...


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*** Here is code sample that you can use to retrieve time from NIST Internet Time Service

var client = new TcpClient("time.nist.gov", 13);
using (var streamReader = new StreamReader(client.GetStream()))
{
var response = streamReader.ReadToEnd();
var utcDateTimeString = response.Substring(7, 17);
var localDateTime = DateTime.ParseExact(utcDateTimeString, "yy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
}

*** I would recommend using time.nist.gov instead of hardcoding the IP Address. Otherwise this is an excellent answer.
***
*** You should use the format string: "yy-MM-dd HH:mm:ss" instead. HH is the 24 hour designation. hh is for 12 hour, see: msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*** Or this...


public static DateTime GetNistTime()
{
DateTime dateTime = DateTime.MinValue;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://nist.time.gov/actualtime.cgi?lzbc=siqm9b");
request.Method = "GET";
request.Accept = "text/html, application/xhtml+xml, */*";
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";
request.ContentType = "application/x-www-form-urlencoded";
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); //No caching
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
StreamReader stream = new StreamReader(response.GetResponseStream());
string html = stream.ReadToEnd();//<timestamp time=\"1395772696469995\" delay=\"1395772696469995\"/>
string time = Regex.Match(html, @"(?<=\btime="")[^""]*").Value;
double milliseconds = Convert.ToInt64(time) / 1000.0;
dateTime = new DateTime(1970, 1, 1).AddMilliseconds(milliseconds).ToLocalTime();
}

return dateTime;
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Web Server Date-Time

Post by pctoledo »

Check the URLs are active.

Enter the DOS prompt and type:

C:\>ping time.windows.com

See if there's some return, for example:
ping.jpg
ping.jpg (68.11 KiB) Viewed 5881 times
andyglezl wrote:* cDataHora:= GetDataTimeNtp( "131.107.13.100") // "time.nist.gov"
correct ip: 128.138.141.172
Regards/Saludos,

Toledo

Clipper On Line
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Web Server Date-Time

Post by andyglezl »

Debe de haber algo mal, ya que "time.nist.gov" me da una IP diferente...
----------------------------------------------------------------------------------------
There must be something wrong, because "time.nist.gov" gives me a different IP ...
ping.jpg
ping.jpg (307.75 KiB) Viewed 5876 times
Andrés González López
Desde Guadalajara, Jalisco. México.
Post Reply