一个按钮把系统时间调整到跟IE一致
代码……
50分
VB 调整系统时间
答案:3 悬赏:0 手机版
解决时间 2021-02-20 23:53
- 提问者网友:末路
- 2021-02-20 00:25
最佳答案
- 五星知识达人网友:孤独入客枕
- 2021-02-20 00:35
你重新复制一遍我给你的代码,现在好使
话一个Winsock1控件
Option Explicit
'采用RFC867 Daytime协议获取标准时间例程
'www.time.ac.cn为中科院国家授时中心,采用北京时间
'时间格式:Mon Jul 26 09:58:57 2004
'time.nist.gov为美国标准技术院,采用格灵威时间
'时间格式:53212 04-07-26 02:00:12 50 0 0 488.3 UTC(NIST) *
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim NoSrv As Boolean
Dim TimeFromNet
Private Sub Form_Load()
Winsock1.Protocol = sckTCPProtocol '采用TCP协议
NetTime "www.time.ac.cn" '首先取中科院国家授时中心时间
If NoSrv Or TimeFromNet = "" Then
'若未取到中科院国家授时中心时间,则取美国标准技术院时间
NetTime "time.nist.gov"
If NoSrv Or TimeFromNet = "" Then
'若不能取美国标准技术院时间,则报错
MsgBox "检测不到网络标准时间服务器time.nist.gov!"
Else
'为使网络传输误差减小,第2次再取美国标准技术院时间
NetTime "time.nist.gov"
If TimeFromNet = "" Then
MsgBox "网络标准时间服务器time.nist.gov超时!"
Else
TimeFromNet = Mid(TimeFromNet, 17, 8)
TimeFromNet = TimeSerial((Hour(TimeFromNet) + 8) Mod 24, Minute(TimeFromNet), Second(TimeFromNet))
Time = TimeFromNet '设置系统时间
End If
End If
Else
'为使网络传输误差减小,第2次再取中科院国家授时中心时间
NetTime "www.time.ac.cn"
If TimeFromNet = "" Then
MsgBox "网络标准时间服务器www.time.ac.cn超时!"
Else
Time = Mid(TimeFromNet, 12, 8) '设置系统时间
End If
End If
End
End Sub
'关闭Winsock子程序
Private Sub Winsock1_Close()
If Winsock1.State <> sckClosed Then
Winsock1.Close
End If
End Sub
'Winsock接收数据事件
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
TimeFromNet = String(bytesTotal, " ")
Winsock1.GetData TimeFromNet, vbString, bytesTotal
End Sub
'Winsock出错事件
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
NoSrv = True
End Sub
'从互联网上标准时间提供网站获取标准时间
Private Sub NetTime(TimeSrv As String)
NoSrv = False
TimeFromNet = ""
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.RemoteHost = TimeSrv ' "www.time.ac.cn" 或 "time.nist.gov"
Winsock1.RemotePort = 13
Winsock1.LocalPort = 0
Winsock1.Connect
Do While TimeFromNet = "" '循环等待标准时间网站返回时间数据
If NoSrv Then Exit Do '若Winsock出错,则跳出循环等待
Sleep 55
DoEvents
Loop
If Winsock1.State <> sckClosed Then Winsock1.Close
End Sub
话一个Winsock1控件
Option Explicit
'采用RFC867 Daytime协议获取标准时间例程
'www.time.ac.cn为中科院国家授时中心,采用北京时间
'时间格式:Mon Jul 26 09:58:57 2004
'time.nist.gov为美国标准技术院,采用格灵威时间
'时间格式:53212 04-07-26 02:00:12 50 0 0 488.3 UTC(NIST) *
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim NoSrv As Boolean
Dim TimeFromNet
Private Sub Form_Load()
Winsock1.Protocol = sckTCPProtocol '采用TCP协议
NetTime "www.time.ac.cn" '首先取中科院国家授时中心时间
If NoSrv Or TimeFromNet = "" Then
'若未取到中科院国家授时中心时间,则取美国标准技术院时间
NetTime "time.nist.gov"
If NoSrv Or TimeFromNet = "" Then
'若不能取美国标准技术院时间,则报错
MsgBox "检测不到网络标准时间服务器time.nist.gov!"
Else
'为使网络传输误差减小,第2次再取美国标准技术院时间
NetTime "time.nist.gov"
If TimeFromNet = "" Then
MsgBox "网络标准时间服务器time.nist.gov超时!"
Else
TimeFromNet = Mid(TimeFromNet, 17, 8)
TimeFromNet = TimeSerial((Hour(TimeFromNet) + 8) Mod 24, Minute(TimeFromNet), Second(TimeFromNet))
Time = TimeFromNet '设置系统时间
End If
End If
Else
'为使网络传输误差减小,第2次再取中科院国家授时中心时间
NetTime "www.time.ac.cn"
If TimeFromNet = "" Then
MsgBox "网络标准时间服务器www.time.ac.cn超时!"
Else
Time = Mid(TimeFromNet, 12, 8) '设置系统时间
End If
End If
End
End Sub
'关闭Winsock子程序
Private Sub Winsock1_Close()
If Winsock1.State <> sckClosed Then
Winsock1.Close
End If
End Sub
'Winsock接收数据事件
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
TimeFromNet = String(bytesTotal, " ")
Winsock1.GetData TimeFromNet, vbString, bytesTotal
End Sub
'Winsock出错事件
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
NoSrv = True
End Sub
'从互联网上标准时间提供网站获取标准时间
Private Sub NetTime(TimeSrv As String)
NoSrv = False
TimeFromNet = ""
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.RemoteHost = TimeSrv ' "www.time.ac.cn" 或 "time.nist.gov"
Winsock1.RemotePort = 13
Winsock1.LocalPort = 0
Winsock1.Connect
Do While TimeFromNet = "" '循环等待标准时间网站返回时间数据
If NoSrv Then Exit Do '若Winsock出错,则跳出循环等待
Sleep 55
DoEvents
Loop
If Winsock1.State <> sckClosed Then Winsock1.Close
End Sub
全部回答
- 1楼网友:醉吻情书
- 2021-02-20 00:58
IE时间?
- 2楼网友:不想翻身的咸鱼
- 2021-02-20 00:43
time "12:00:00" 这个就是设置时间的,如果你要用IE的就先从网上获取IE时间
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯