Click here to Skip to main content
14,422,439 members
Rate this:
Please Sign up or sign in to vote.
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://").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
Updated 12-Jan-20 22:37pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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[^]
CPallini 13-Jan-20 3:40am
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100