加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB.NET中修改系统的时间

发布时间:2020-12-17 08:19:12 所属栏目:百科 来源:网络整理
导读: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 P
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读