setting system date and time from my code

  • Thread starter Thread starter Ravi
  • Start date Start date
R

Ravi

hi,
I was wondering what methods there are to set the system
time from within my code.
I'm looking to sync with an internet time server and take
time going forward, as being from there.
thanks
Ravi
 
Ravi said:
hi,
I was wondering what methods there are to set the system
time from within my code.

Is there FAQ section in this newsgroup?
I think such questions should be placed there.

<StructLayout(LayoutKind.Sequential)> Public Class SystemTime
Public wYear As System.UInt16
Public wMonth As System.UInt16
Public wDayOfWeek As System.UInt16
Public wDay As System.UInt16
Public wHour As System.UInt16
Public wMinute As System.UInt16
Public wSecond As System.UInt16
Public wMilliseconds As System.UInt16
End Class

<DllImport("coredll.dll", Entrypoint:="SetSystemTime",
setLastError:=True)> _
Public Function SetSystemTime( _
ByVal lpSystemTime As SystemTime _
) As Boolean
End Function
<DllImport("coredll.dll", Entrypoint:="CeRapiInitEx",
setLastError:=True)> _
Public Function CeRapiInitEx( _
ByVal lpSystemTime As SystemTime _
) As Boolean
End Function

<DllImport("coredll.dll", Entrypoint:="GetSystemTime",
setLastError:=True)> _
Public Sub GetSystemTime( _
ByVal lpSystemTime As SystemTime _
)
End Sub

Public Sub SetSysDateTime(ByVal newdate As DateTime)
Dim dt As DateTime =
TimeZone.CurrentTimeZone.ToUniversalTime(newdate)
Dim systime As New SystemTime
systime.wYear = Convert.ToUInt16(dt.Year)
systime.wMonth = Convert.ToUInt16(dt.Month)
systime.wDay = Convert.ToUInt16(dt.Day)
systime.wHour = Convert.ToUInt16(dt.Hour)
systime.wMinute = Convert.ToUInt16(dt.Minute)
systime.wSecond = Convert.ToUInt16(dt.Second)
SetSystemTime(systime)

End Sub
 
Back
Top