我的一个程序,只允许每月的单数日的双数时间才能运行。如今天是3月30号,今天一天都不能运行明天是3月31日,明天的1,3,5,7,11,13,15,17,19,21,23点可以运行。算法部分我倒也没有什么问题,难度就是:如果有人把这台机器的系统时间随意更改,我这个设计就毫无意义。我想请大家谁能给出取得当前真实时间的办法?不论它怎么改自己的系统时间,我的程序都能判断出现在的真实时间!我想,也只有上网验证才可以了,但是不知道哪里能有时时提供当前时间的地方,。而且能被我的VB程序读到? 我倒是有一个FTP服务器和WEB服务器,我在上面上了一个页面,但是我得每隔1小时去更新一下他的页面,异常痛苦。现在:1)谁能解决网页时间自动更新的问题,假如一个网页 http://www.myweb.com/time.ini 里面有一个时间串, 20:15 我希望在21点15分的时候,time.ini里面的字符串能自动变成21:15
如果上面实现起来有难度,第二方案:
2)谁能提供一个全天24小时无休的准确提供当前真实的东八区(适用于中华人民共和国大陆地区)的时间, 别说time.microsoft.com 哦! 我10次连他9次失败!!或者您有更加好的解决办法,请跟帖讨论。谢谢。
如果上面实现起来有难度,第二方案:
2)谁能提供一个全天24小时无休的准确提供当前真实的东八区(适用于中华人民共和国大陆地区)的时间, 别说time.microsoft.com 哦! 我10次连他9次失败!!或者您有更加好的解决办法,请跟帖讨论。谢谢。
解决方案 »
- vb怎么获取当前线程???
- 新手求教:不同窗口间参数的调用问题
- 请问,我使用vb创建一个activex,如何为这个控件增加自定义的事件???
- 各位谁有没有租过SQL数据库空间???
- 怎么让程序暂停20秒再往下执行?
- 大家谁哪里还有下载VB6SP5,我用WISE做安装程序,说要下载一个VB6SP5,但下载过程中中断了,别告诉我去微软,因为我看了一下有100多M,是
- 哪位可以给推荐一下通过程序用conn.excute sql 增加、删除、修改ACCESS表、字段的书。
- 请高手帮忙解决``非常感谢 ````
- 为什么现在还有人学vb
- 【过年了,程序等着打包,安装程序在桌面上创建快捷图标的问题,高手请进,急!!!
- 项目顶在头上,还不知道怎么入手???
- 在一个Form里,是不是不能用两个名来引用同一个数据库?
但是我该如何与他们交流?从他们那里得到现在的确切时间?
我找到了一个代码窗体:Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As LongPrivate Sub Command1_Click() 'Main button to set the system
' time
On Error GoTo ErrHandler Label3.Caption = "System Time has Not been Set Yet" SetIt = 1 'Used to only set time if the time from the
' time server is valid and reportedly accurate If Winsock1.State <> sckClosing Then 'Sometimes the
' Winsock gets delayed in the closing state, so
' make sure it is closed before trying again
If Winsock1.State = sckClosed Then 'If closed, ok to
' open, else close it
Timer1.Interval = 5000 'Start 5 second count to
' 'time' server
Timer1.Enabled = True
Screen.MousePointer = vbHourglass
Winsock1.LocalPort = 0 'Must be set to 0
Winsock1.RemoteHost = Trim$(Text1.Text) 'Address
' of NIST server
Winsock1.RemotePort = 13 '13, 37 or 123 'Use 13!
Winsock1.Protocol = 0 '1-UDP '0-TCP 'USE TCP!
Winsock1.Connect 'This is what goes out and gets
' the time
Else
Winsock1.Close
Screen.MousePointer = vbNormal
Timer1.Interval = 0
Timer1.Enabled = False
End If
Else
Winsock1.Close
Screen.MousePointer = vbNormal
Timer1.Interval = 0
Timer1.Enabled = False
End If
Exit Sub
ErrHandler:
SetIt = 0
Screen.MousePointer = vbNormal
Timer1.Interval = 0
Timer1.Enabled = False
MsgBox "The Winsock Connection is Unavailable."
Winsock1.Close
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) _
'Fires when data is received from server
Dim datDate As Date 'formatted date
Dim strData As String 'time string from net time server
Dim JSys As SYSTEMTIME
Dim RetVal As Integer
Dim Ct As Integer On Error GoTo ErrHandler
Winsock1.GetData strData, vbString 'get string from
' server
datDate = FormatDateTime(strData) 'go format the new
' string
If msAdj <> 0 Then 'if msadj = 0 then do not set an
' offset
datDate = DateAdd("s", -1, datDate) 'only if msadj
' <> 0, subtract 1 sec from new time so addition
' of msadj is positive
End If
Label1.Caption = "Before " & Now 'time before adjustment
If SetIt = 1 Then 'If all is ok, set system time
'Initialize SYSTIME with new data
JSys.wYear = Year(datDate)
JSys.wMonth = Month(datDate)
JSys.wDayOfWeek = 0 'DayOfWeek(datDate)'Not used
JSys.wHour = Hour(datDate)
JSys.wMinute = Minute(datDate)
JSys.wSecond = Second(datDate)
JSys.wDay = Day(datDate)
MsgBox JSys.wMinute
If msAdj = 0 Then
JSys.wMilliseconds = 0 'No millisec offset
Else
JSys.wMilliseconds = ((10000 - msAdj) / 10) 'must
' be positive
End If
'Set system time with new data
Do Until RetVal <> 0 Or Ct > 9 'Make up to 10
' attempts to set the time
RetVal = SetSystemTime(JSys)
Ct = Ct + 1
Loop
Label2.Caption = "After " & Now 'time after
' adjustment
If RetVal <> 0 Then
Label3.Caption = "System Time was Set " & _
"Successfully"
Else
Label3.Caption = "There was an Error in Setting " & _
"Time"
End If
'Display time string that was sent from server
Text2.Text = strData
End If
SetIt = 0
Winsock1.Close
Screen.MousePointer = vbNormal
Timer1.Interval = 0
Timer1.Enabled = False
Exit Sub
ErrHandler:
SetIt = 0
Winsock1.Close
Screen.MousePointer = vbNormal
Timer1.Interval = 0
Timer1.Enabled = False
End Sub模版:
Type SYSTEMTIME ' 16 Bytes
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type我再Text1.Text里面输入:nist1-sj.glassey.com点了Command1,Label3.caption一直显示System Time has Not been Set Yet沙漏后没有反应!
这个文件的唯一功能就是生成一个 text 框,里面放的是web服务器的当前日期/时间;
然后用你的程序通过 webbrowser 控件访问这个文件,获取 text 框的内容即可。注意:如果WEB服务器不是你自己能控制的,请注意时差问题。比如如果使用美国的服务器,得到 text 内容后要调整时差才是正确的数据。
Dim HTTP As XMLHTTP
Public Function GetTheContent(src As String) As String 'src 目标URL地址
Set HTTP = New XMLHTTPIf src <> "" Then
HTTP.open "GET", src, False
HTTP.send
If HTTP.readyState <> 4 Then
Exit Function
End If
GetTheContent = BytesToBstr(HTTP.responseBody, "GB2312")
Set HTTP = Nothing
If Err.Number <> 0 Then Err.Clear
Else
GetTheContent = "no source"
End If
End FunctionPrivate Function BytesToBstr(body, Cset) As String '文字转换
Dim objstream As New ADODB.streamobjstream.Type = 1
objstream.Mode = 3
objstream.open
objstream.Write bodyobjstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
End Function窗体中Private Sub Command1_Click()
Dim freeNO As Integer
Dim strGet As String
freeNO = FreeFile
strGet = GetTheContent("http://www.people.com.cn/")
If strGet = "" Then
MsgBox "get failed"
Exit Sub
End If
Open "c:\1.txt" For Output As freeNO Write #freeNO, strGet
Close #freeNO
End Sub打开 记事本你就可以看到日期了。(2005年03月31日 星期四)以下的查找打操作很简单,相信你自己能搞定了。
用以上链接中ch21st(www.blanksoft.com)回复中的代码,可以得到一个字符串,分析出时间