Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I try get datetime from internet not system time but internet time, How can I get datetime in specific format? Works right only this:

Label4.Text = DateTime.ParseExact(myHttpWebRequest.Headers("date"), "ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal)


I need for label2 - yyyyMMdd HH:mm:ss
for label3 - HH:mm:ss

Thank you

What I have tried:

 Public Sub internet_date(sender As Object, e As EventArgs)
        Dim myHttpWebRequest = WebRequest.Create("Http://www.microsoft.com").GetResponse()
        Label2.Text = DateTime.ParseExact(myHttpWebRequest.Headers("date"), "HH:mm:ss 'GMT'", CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal)
Label3.Text = DateTime.ParseExact(myHttpWebRequest.Headers("date"), "yyyyMMdd HH:mm:ss 'GMT'", CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal)
end sub
Posted
Updated 12-Jan-20 21:37pm

1 solution

There is no such thing as "internet time" - there is only one "time" that is the same across the world and that is UTC - Coordinated Universal Time (it started in French so the acronym doesn't match the actual name: usie UTC and you'll be fine).

You can get that from any system in VB : DateTime.UtcNow Property (System) | Microsoft Docs[^] or you can query an NTP server on the internet: NTP Server Time[^]
 
Share this answer
 
Comments
CPallini 13-Jan-20 3:40am    
5.
phil.o 13-Jan-20 4:38am    
That's not French either :) A French acronym would be TUC. UTC is just a compromise between CUT and TUC.
OriginalGriff 13-Jan-20 4:52am    
Shows how good my French is! :laugh:
I was assured years ago it was "Universel Temps Coordonné" - so I'll have to track someone down and have them beaten quite severely.

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