如何在vb.net中通过单击按钮更正系统时间

如何在vb.net中通过单击按钮更正系统时间,.net,vb.net,time,.net,Vb.net,Time,我已经创建了一个时间更正应用程序,当单击“更正时间”按钮时,该应用程序会更正系统时间。我如何将系统时间更改为当前时间。我将为时间错误的计算机使用该应用程序 'create a datetime object with the current time Dim correctTime = DateTime.Now() 'adjust the time correctTime.AddSeconds(1) 'set the time on your machine Try Microsoft

我已经创建了一个时间更正应用程序,当单击“更正时间”按钮时,该应用程序会更正系统时间。我如何将系统时间更改为当前时间。我将为时间错误的计算机使用该应用程序

'create a datetime object with the current time
Dim correctTime = DateTime.Now()
'adjust the time
correctTime.AddSeconds(1)

'set the time on your machine
Try
    Microsoft.VisualBasic.TimeOfDay = correctTime
Catch ex As Exception
    MessageBox.Show("Could not set the time. You probably need to run as Administrator to do this. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
End Try
您需要以“管理员”的身份运行以调整时间,尽管这可能是非常有效的。另请参见。可能的副本