Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want one or more functions to open or trace a website and search in it's source codes then returns the server time.

What I have tried:

I found some code but if I want to say honestly, I wasn't testing them because they were very complex. here's <a href="https://www.codeproject.com/Questions/743287/How-do-I-get-TimeZone-of-another-Remote-Server-in"></a>. I think this must be very simple and c# has a simple function for that.
Posted
Updated 7-Jul-19 1:00am
v2

1 solution

Just ask Google:
C#
public static DateTime GetInternetTime()
    {
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.Google.com");
    WebResponse response = myHttpWebRequest.GetResponse();
    string todaysDates = response.Headers["date"];
    return DateTime.ParseExact(todaysDates,
                               "ddd, dd MMM yyyy HH:mm:ss 'GMT'",
                               CultureInfo.InvariantCulture.DateTimeFormat,
                               DateTimeStyles.AssumeUniversal);
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900