简体   繁体   English

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

[英]How to correct system time with a button click in vb.net

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

'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

You will need to be running "As Admin" to adjust the time though您需要以“管理员身份”运行来调整时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM