I am trying to develop an application, where it wont rely on the current system time;
Even when I change the date and time on my PC/System, it wont change.
I am trying to develop an application, where it wont rely on the current system time;
Even when I change the date and time on my PC/System, it wont change.
Unfortunately if you want to measure time intervals, you need to choose a clock as a reference. Reading your other question and your comments, I get the impression that you just want to know how much time elapsed since a given time instance.
If you just worry about the daylight changing in spring and autumn, you should just use the system time as UTC:
Public StartDate As Date = Date.UtcNow
...
Dim elapsed As TimeSpan = Date.UtcNow - StartDate
If you also want to ignore when a system administrator changes the system time, you need to rely on the high-precision counter of the CPU (although that cannot be used to measure time between different runs of your program):
Imports System.Diagnostics
...
Dim myClock As New StopWatch()
myClock.Start()
...
Dim elapsed As TimeSpan = myClock.Elapsed
And if you would like to use the system time on the database server, you should query that:
Dim query As String = "SELECT GETDATE()"
Using connection As New SqlConnection("your connection string here"), _
cmd As New SqlCommand(query, connection)
connectionn.Open()
Dim timeOnSqlServer As Date = Convert.ToDateTime(cmd.ExecuteScalar())
End Using