VB: Retrieve the time from a time server.
Solved
Anonyme209
Posted messages
761
Status
Membre
-
cs_Le Pivert Posted messages 8437 Status Contributeur -
cs_Le Pivert Posted messages 8437 Status Contributeur -
Hello,
I am programming in Visual Basic 2010.
I would like to be able to synchronize the system time with the time of a web time server. To modify the system time, I found "TimeString = "hh:mm:ss"", but it only works in admin mode. And I don't know how to retrieve the time from a web server.
Thank you for your help.
I am programming in Visual Basic 2010.
I would like to be able to synchronize the system time with the time of a web time server. To modify the system time, I found "TimeString = "hh:mm:ss"", but it only works in admin mode. And I don't know how to retrieve the time from a web server.
Thank you for your help.
12 réponses
Thank you, I will use the project's code and adapt it for my program.
If it's not too much to ask, there are still three other points that could be useful to me:
- Retrieve the date from the internet (I should be able to manage on my own)
- Automatically detect whether it is daylight saving time or standard time.
- Modify the system time without starting in admin mode (I don't think that's possible, but I'm asking anyway)
Thank you for your help.
If it's not too much to ask, there are still three other points that could be useful to me:
- Retrieve the date from the internet (I should be able to manage on my own)
- Automatically detect whether it is daylight saving time or standard time.
- Modify the system time without starting in admin mode (I don't think that's possible, but I'm asking anyway)
Thank you for your help.
For the first point, you need to change the address:
address = "https://ntp.alapetite.fr/date.txt.php"
and then in Private Sub Timer1_Tick:
For the second point, look in the string manipulation to find the 2
I don't know about the third point, you will need to make a new post.
Happy coding
--
@+ Le Pivert
address = "https://ntp.alapetite.fr/date.txt.php"
and then in Private Sub Timer1_Tick:
Dim s As String = texte 'string manipulation Dim separateur As Char = CChar("T") Dim nom() As String nom = s.Split(separateur) lbldate.Text = nom(0) For the second point, look in the string manipulation to find the 2
I don't know about the third point, you will need to make a new post.
Happy coding
--
@+ Le Pivert
Hello,
Thank you for your help.
I know that changing the 2 to a 1 in the address allows you to display either summer time or winter time.
What I would like is to automatically detect whether to use a 2 or a 1.
Thank you for your help.
I know that changing the 2 to a 1 in the address allows you to display either summer time or winter time.
What I would like is to automatically detect whether to use a 2 or a 1.
You need to check the calendar for the transition from summer time to winter time and vice versa, and with the date you retrieve from lbldate.Text, you just need to do an If
The change is on 26-10-2014 so:
There, it's not more complicated than that
--
@+ Le Pivert
The change is on 26-10-2014 so:
If lbldate.Text = 26/10/2014 Then' you'll need to check the Date format and correct if necessary adress = "http://www.Heure.com/heure-fr.php?timezone=1&size=36" End If
There, it's not more complicated than that
--
@+ Le Pivert
Hello,
Thank you for the reply, but there is just one problem:
It only works for the winter time change in 2014.
I would like it to work all the time.
(For example, look on the calendar for the change from summer time to winter time directly in vb)
Thank you for the reply, but there is just one problem:
It only works for the winter time change in 2014.
I would like it to work all the time.
(For example, look on the calendar for the change from summer time to winter time directly in vb)
To do this, we need to check the week numbers; I think it's always the same weeks: the last Sunday of March (14) and of October (44). So, we need to perform a search to find the current week number that we will store in a variable (masemaine) which will be set when the application opens. Then, upon opening, we just need to do:
If masemaine = 14 then
we change the time
end if
I'll leave it to you to do a Google search to find the current week number in VB.NET
This will change on Monday; afterwards, we can refine it with the dates. It's up to you
--
@+ Le Pivert
If masemaine = 14 then
we change the time
end if
I'll leave it to you to do a Google search to find the current week number in VB.NET
This will change on Monday; afterwards, we can refine it with the dates. It's up to you
--
@+ Le Pivert
I found a source in VB6 to determine the days of the time changes. I adapted it to VB.Net if you're interested, you can integrate it into your program.
In a Form, put a Button and 2 Labels, here's the code with the link to the VB6 source:
Happy programming
--
@+ Le Pivert
In a Form, put a Button and 2 Labels, here's the code with the link to the VB6 source:
Option Strict On Public Class Form1 'http://codes-sources.commentcamarche.net/source/24735-calcul-du-decalage-heure-ete-hiver-en-fonction-d-une-date Dim seuilete As Date Dim seuilhiver As Date Dim dteData As Date Dim iddate As String Dim jour As Integer Dim uneDateC As Decimal 'number of days since the beginning of the year Dim seuileteC As Decimal 'day of the start of summer time Dim seuilhiverC As Decimal 'day of the start of winter time Dim DateS As String Dim DateD As DateTime Dim Annee As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'updating the dates dteData = Now 'today Annee = (dteData.ToString("yyyy")) 'current year 'uneDate = CDate(TextBox1.Text) iddate = "25/03/" & Annee & " 02:00:00" 'it's March 25th of the same year seuilete = CDate(iddate) jour = Weekday(seuilete, vbMonday) 'how many days until the next Sunday? iddate = (32 - jour) & "/03/" & Annee & " 02:00:00" seuilete = CDate(iddate) Label1.Text = "summer time: " & Format(seuilete, "dddd d MMM yyyy") '---------------------------------------------------------------------- 'same for winter time 'it's October 25th of the same year iddate = "25/10/" & Annee & " 02:00:00" seuilhiver = CDate(iddate) jour = Weekday(seuilhiver, vbMonday) 'how many days until the next Sunday? iddate = (32 - jour) & "/10/" & Annee & " 02:00:00" seuilhiver = CDate(iddate) Label2.Text = "winter time: " & Format(seuilhiver, "dddd d MMM yyyy") '-------------------------------------------------------------------- 'a little comparison DateS = ("01/01/" & Annee) 'Enter a date: we retrieve a string DateD = CDate(DateS) 'Convert the string to DateTime uneDateC = DateDiff(DateInterval.Day, DateD, Now) MsgBox("Today " & uneDateC & " days since the beginning of the year") seuileteC = DateDiff(DateInterval.Day, DateD, seuilete) 'difference in days from the beginning of the year to summer time MsgBox("Summer time is in " & seuileteC & " days since the beginning of the year") seuilhiverC = DateDiff(DateInterval.Day, DateD, seuilhiver) 'difference in days of winter time at the end of the year MsgBox("Winter time is in " & seuilhiverC & " days since the beginning of the year") If (seuileteC < uneDateC) And (uneDateC < seuilhiverC) Then MsgBox("We are in summer time") Else MsgBox("We are in winter time") End If End Sub End Class Happy programming
--
@+ Le Pivert
I made an update if you're interested
https://codes-sources.commentcamarche.net/source/100641-obtenir-l-heure-du-jour-depuis-le-web-en-vb-net
--
@+ The Woodpecker
https://codes-sources.commentcamarche.net/source/100641-obtenir-l-heure-du-jour-depuis-le-web-en-vb-net
--
@+ The Woodpecker
You gave me the idea to create a time-limited evaluation software based on the web date. If you’re interested:
https://codes-sources.commentcamarche.net/source/100652-logiciel-d-evaluation-a-duree-determinee
Best regards
--
@+ Le Pivert
https://codes-sources.commentcamarche.net/source/100652-logiciel-d-evaluation-a-duree-determinee
Best regards
--
@+ Le Pivert