用VB获取北京时间
2个回答
展开全部
在窗体上添加一个命令按钮command1、一个Label1和一个Inet1控件,复制以下代码即可:
Private Sub Command1_Click()
Dim StrCoding As String
StrCoding = Inet1.OpenURL("http://www.time.ac.cn/stime.asp")
Dim Time0 As String, date0 As String
Time0 = Right(Split(StrCoding, "年")(0), 4) & "年" & Split(Split(StrCoding, "年")(1), "日")(0) & "日"
date0 = Left(Split(StrCoding, "var hrs = ")(1), 2) & ":" & Left(Split(StrCoding, "var min = ")(1), 2) & ":" & Left(Split(StrCoding, "var sec = ")(1), 2)
Label1.Caption = Time0 & " " & date0
End Sub
Private Sub Command1_Click()
Dim StrCoding As String
StrCoding = Inet1.OpenURL("http://www.time.ac.cn/stime.asp")
Dim Time0 As String, date0 As String
Time0 = Right(Split(StrCoding, "年")(0), 4) & "年" & Split(Split(StrCoding, "年")(1), "日")(0) & "日"
date0 = Left(Split(StrCoding, "var hrs = ")(1), 2) & ":" & Left(Split(StrCoding, "var min = ")(1), 2) & ":" & Left(Split(StrCoding, "var sec = ")(1), 2)
Label1.Caption = Time0 & " " & date0
End Sub
追问
谢谢你的回答,但不知道你是否运行过。 我之前也曾在网上找到过这段代码,运行时会报错,和你的代码一模一样。。。
追答
你必须新建一个窗体,在form1上新建一个命令按钮command1、一个Label1和一个Inet1控件
输入以上代码,点击command1,Label1就可以获取时间。如果报错,根据错误代码添加合适的控件,此程序已测,能用,联网稍慢,不要狂点command1。
展开全部
Private Sub Command1_Click()
Dim StrCoding As String
StrCoding = Inet1.OpenURL("http://www.time.ac.cn/stime.asp")
Dim Time0 As String, date0 As String
Time0 = Right(Split(StrCoding, "年")(0), 4) & "年" & Split(Split(StrCoding, "年")(1), "日")(0) & "日"
date0 = Left(Split(StrCoding, "var hrs = ")(1), 2) & ":" & Left(Split(StrCoding, "var min = ")(1), 2) & ":" & Left(Split(StrCoding, "var sec = ")(1), 2)
Label1.Caption = Time0 & " " & date0
Date = "" & Time0 & " " & date0
End Sub
注意添加部件
工程----部件----Micr.....internet tr....打上勾确定 然后你在去加一个控件就可以运行改时间了,,你把时间改下 然后再用这程序改回来
Dim StrCoding As String
StrCoding = Inet1.OpenURL("http://www.time.ac.cn/stime.asp")
Dim Time0 As String, date0 As String
Time0 = Right(Split(StrCoding, "年")(0), 4) & "年" & Split(Split(StrCoding, "年")(1), "日")(0) & "日"
date0 = Left(Split(StrCoding, "var hrs = ")(1), 2) & ":" & Left(Split(StrCoding, "var min = ")(1), 2) & ":" & Left(Split(StrCoding, "var sec = ")(1), 2)
Label1.Caption = Time0 & " " & date0
Date = "" & Time0 & " " & date0
End Sub
注意添加部件
工程----部件----Micr.....internet tr....打上勾确定 然后你在去加一个控件就可以运行改时间了,,你把时间改下 然后再用这程序改回来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询