求助,VB.Net设置系统时间问题
1个回答
2017-06-08
展开全部
<pre class="html" name="code"> </pre><pre class="html" name="code">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</pre><br>
<pre></pre>
<pre class="vb" name="code"> </pre><pre class="vb" name="code"> </pre><pre class="vb" name="code"> </pre>
<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</pre><br>
<pre></pre>
<pre class="vb" name="code"> </pre><pre class="vb" name="code"> </pre><pre class="vb" name="code"> </pre>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询