且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VB.NET更改Windows系统日期时间

更新时间:2023-12-02 10:08:28

你不需要任何这样做你想要的。您可以使用 Microsoft.VisualBasic 命名空间来实现此目的。以下是您需要的简短示例。

You don't need any of that to do what you want. You can use Microsoft.VisualBasic namespace to accomplish this. Here's a short example for what you need. This is tried and tested as well.

Private Sub ChangeDate()
   Dim d As DateTime
   d = "22:30:00"

   Try
      Microsoft.VisualBasic.TimeOfDay = d 'Your time...
      Microsoft.VisualBasic.DateString = New Date(1978, 4, 28) 'The date...
   Catch ex As Exception
      'You might have to run as Administrator...?
   End Try

End Sub