以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]網路時間  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=85908)

--  作者:PeterGu
--  发布时间:2016/6/5 15:32:00
--  [求助]網路時間
之前參考了老師的代碼來獲取網路時間
    Dim url As String = "http://foxtable.sinaapp.com/time/"
    Dim rqst As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url)
    Dim rsps As System.Net.HttpWebResponse = rqst.GetResponse
    Dim stm As System.IO.Stream = rsps.GetResponseStream()
    Dim reader As New System.IO.StreamReader(stm)
    Dim str As String = reader.ReadToEnd
    stm.Dispose()
    Dim dt As Date = str 
    MessageBox.show(dt)

可是現在連不上那個時間伺服器(之前是可以的),不知道是否因為人不在中國大陸的關係。
請問有解決辦法嗎?比方如果我想用其他網站的時間
http://www.worldtimeserver.com/current_time_in_TW.aspx


--  作者:大红袍
--  发布时间:2016/6/5 15:35:00
--  

Dim url As String = "http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json"
Dim rqst As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url)
Dim rsps As System.Net.HttpWebResponse = rqst.GetResponse
Dim stm As System.IO.Stream = rsps.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim str As String = reader.ReadToEnd
stm.Dispose()
Output.Show(str)

Dim data As object
Dim JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
Dim ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", str)
End With

Dim d As Date = data.result.datetime_1

msgbox(d)


--  作者:PeterGu
--  发布时间:2016/6/5 15:37:00
--  
謝謝老師