0
I need to search the date acts from the Internet, in the code below the return is the date, hour, 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);
}
As I search only the date, since just deleting the section HH:mm:ss
doesn’t work?
Return format:
What if you just convert to datetime? Then you can convert to any format you want. What format do you expect?
– Aline
@Aline I edited the code
– Marlon Pereira
What format do you want? dd/MM/yyyy??
– Aline
Yes: dd/MM/yyyy
– Marlon Pereira
Young man, your code is right, man. Show me the part that does the
MessageBox.Show
– Jéf Bueno
MessageBox.Show(GetNistTime().ToString());
– Marlon Pereira
Messagebox.Show(Getnisttime(). Toshortdatestring());
– Rovann Linhalis
And, tell me, what is your intention? Show in Messagebox without the time?
– Jéf Bueno
The intention is to save the current date, ex: 05/30/2017 in the database
– Marlon Pereira
And why don’t you save her then?
– Jéf Bueno
'Cause I’m gonna need to compare bank dates to the current date, and time, in which case it’s gonna mess me up, I got the answer down there, thank you!
– Marlon Pereira
@jbueno And as I add days to save to database, for example today is day 25, adding 5 days, would day 30?
– Marlon Pereira
data.AddDays(5)
– Jéf Bueno