Link to home
Start Free TrialLog in
Avatar of bish wakim
bish wakim

asked on

getting Date from the internet with delphi

I work with Delphi Rad seattle 10.
My program needs to get the real date from the internet.
It would be better if could get the date from the server of my site
I am using FireDac which  enables me to connect to external server.
Avatar of Owen Rubin
Owen Rubin
Flag of United States of America image

Does your Delphi include the NOW command?

var
  today : TDateTime;
begin
  today := Now;
  ShowMessage('today has date = '+DateToStr(today));
  ShowMessage('today has time = '+TimeToStr(today));
end;

Got this from this link:  http://www.delphibasics.co.uk/RTL.asp?Name=Now
Avatar of bish wakim
bish wakim

ASKER

Yes it includes this commanf. HowEver I noticed that the time extracted in this way is given by internal clock of computer.
as a matter of fact  I need to extract the date time from outSide!!
Avatar of aikimark
Is your computer connected to a network?  If so, then a regional/language setting would force the PC to have the network time.
There are plenty of internet sites with APIs that will provide the time and other data.
Example:
http://worldclockapi.com/api/json/est/now

Open in new window

returned this JSON:
{"$id":"1","currentDateTime":"2018-10-13T06:19-04:00","utcOffset":"-04:00:00","isDayLightSavingsTime":true,"dayOfTheWeek":"Saturday","timeZoneName":"Eastern Standard Time","currentFileTime":131838851791438541,"ordinalDate":"2018-286","serviceResponse":null}

Open in new window

Please understand my need and suggest some simple and direct solution!
I published a desktop application that loads some database from a server. I wanted the application to stop working when reaching a particular date. Some users managed to keep the application work by changing the date gived by the PC. So I thought I should force the app to extract date from the internet. Ideally I would want to do that via my server since it is connected to my app...
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for your answer
Why not sync your comuter clock to the internet, then all programs have the right time.

NTP is the protocol that does this, and there are NTP client/servers for almost any plantform..
I just assumed that your computer has its clock synchronized with the outside world. Most computers today use an external link setting to keep their computer synchronized with the outside world.

But you did not specify the reason you did not want to use the inside clock. Now I understand.

However, could you update your answer to point to what worked for you, as the answer you picked says:
If you already have a server/web site, why not make a call to your server?
That is not exactly an answer it is something you said yourself.
Can you also please pick aikimark other answer above that  that shows the code?
That way when the database is searched for the answer, the actual answer also shows up?
Thanks.