Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential)> _
Public Structure SYSTEMTIME
Public Year As Short
Public Month As Short
Public DayOfWeek As Short
Public Day As Short
Public Hour As Short
Public Minute As Short
Public Second As Short
Public Miliseconds As Short
End Structure
'api函数声明
<DllImport("kernel32.dll", CharSet:=CharSet.Ansi)> _
Public Shared Function SetSystemTime(ByRef time As SYSTEMTIME) As Boolean
End Function
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ServerTime As Date = F.G("select getdate()")
ServerTime = ServerTime.AddHours(-8)
Dim t As New SYSTEMTIME()
t.Year = ServerTime.Year()
t.Month = ServerTime.Month()
t.Day = ServerTime.Day
t.Hour = ServerTime.Hour
'这个函数使用的是0时区的时间,对于我们用+8时区的,时间要自己算一下.如要设12点,则为12-8
t.Minute = ServerTime.Minute
t.Second = ServerTime.Second
t.Miliseconds = ServerTime.Millisecond
Dim v As Boolean = SetSystemTime(t)
MessageBox.Show(v)
End Sub