public static bool GetInternetDate1(out DateTime dateTime)
{
//var myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.baidu.com/");
myHttpWebRequest.Timeout = 2000;
try
{
WebResponse response = myHttpWebRequest.GetResponse();
string todaysDates = response.Headers["date"];
DateTime dt = DateTime.ParseExact(todaysDates,
"ddd, dd MMM yyyy HH:mm:ss 'GMT'",
CultureInfo.InvariantCulture.DateTimeFormat,
DateTimeStyles.AssumeUniversal);
dateTime = dt;
return true;
}
catch
{
dateTime = new DateTime();
return false;
}
}
|