怎样用VB编写网络校时程序

解决方案 »

  1.   

    Inet1.Execute "http://www.163.com/", "post"
        Do While Inet1.StillExecuting
         DoEvents
        Loop
        MsgBox "现在是格林尼治时间:"&Inet1.GetHeader("Date")
      

  2.   

    补完了yuyes(无业游民)的代码,SetSystemTime是根据时区设置自动转的~Option ExplicitPrivate Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As LongPrivate Type SYSTEMTIME
      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 TypePrivate Sub Form_Load()
        Dim lpSystemTime As SYSTEMTIME
        Dim currentTime As Date
        Dim xDate As String    Inet1.Execute "http://www.163.com/", "post"
        Do While Inet1.StillExecuting
            DoEvents
        Loop
        
        xDate = Mid(Inet1.GetHeader("Date"), InStr(1, Inet1.GetHeader("Date"), ",", vbTextCompare) + 1)
        
        xDate = Trim(Left(xDate, InStr(1, xDate, "GMT", vbTextCompare) - 1))
        currentTime = CDate(xDate)
        
        With lpSystemTime
            .wYear = DatePart("yyyy", currentTime)
            .wMonth = DatePart("m", currentTime)
            .wDay = DatePart("d", currentTime)
            .wHour = DatePart("h", currentTime)
            .wMinute = DatePart("n", currentTime)
            .wSecond = DatePart("s", currentTime)
            .wMilliseconds = 0
        End With
        Call SetSystemTime(lpSystemTime)
        
        Me.Print "GMT:" & currentTime
        Me.Print "SYS:" & Date & " " & Time
    End Sub
      

  3.   

    获取SQL服务器时间:
    dim con as adodb.connection
    dim rst as adodb.recordset
    dim datetime as string 
    con.connectionstring="......"(略)
    con.openrst.open "select getdate()",con
    datetime=rst(0)
    date=cdate(datetime)
    time=cdate(datetime)
      

  4.   

    局域网,:-)
    shell "cmd.exe /c Net time \\myserver set"
      

  5.   

    测试过了,PASS,楼主该结了不过,最好在
        Me.Print "GMT:" & currentTime
        Me.Print "SYS:" & Date & " " & Time
    这两句前面先把窗体显示出来呵
    me.show
      

  6.   

    在窗体上放一Timer控件,然后在其Timer()下放如下代码,就可以了,不过提前要定义Conn,引用ADO
    '得到服务器系统时间
    Public Sub GetTime()
        Dim rst As ADODB.Recordset
        Set rst = New ADODB.Recordset
        rst.Open "select getdate() as sj", Conn, adOpenDynamic, adLockOptimistic
        Time = rst.Fields("sj")
        rst.Close
    End Sub