Search only WEB date

0

I need to search the date acts from the Internet, in the code below the return is the date, time, minutes and seconds.

public static DateTime GetNistTime()
    {
        var myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
        var 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);
    }

How do I look only at the date, since just deleting the HH:mm:ss stretch does not work?

Return format:

    
asked by anonymous 31.05.2017 / 00:00

2 answers

2

Edit:

You can keep your method as it is, and when it's time to call it, just ignore the time:

public static DateTime GetNistTime()
    {
        var myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
        var 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);
    }

Calling the method:

label1.Text = GetNistTime().ToShortDateString();
    
31.05.2017 / 00:08
2
public static string GetNistTime()
    {
        var myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
        var response = myHttpWebRequest.GetResponse();
        string todaysDates = response.Headers["date"];
        return DateTime.Parse(todaysDates).toString("dd/MM/yyyy");
    }
    
31.05.2017 / 00:11