VB.NET中修改系统的时间

前端之家收集整理的这篇文章主要介绍了VB.NET中修改系统的时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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
原文链接:https://www.f2er.com/vb/259166.html

猜你在找的VB相关文章