明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: 朽木大师

如何读取 世界时间 而非本电脑时间

  [复制链接]
发表于 2012-8-23 17:58:05 | 显示全部楼层
xiaxiang 发表于 2012-8-23 16:18
请教GetNetTimeAPP.dll是如何来的,提供什么接口以供调用?可以开源吗?

Public Function GetNetTime() As String
Dim obj, OBJStatus, url, GetText, i
Dim Retrieval
    url = "http://www.baidu.com"
    '判断网络是否连接
    If url <> "" Then
        Set Retrieval = GetObject("winmgmts:\\.\root\cimv2")
        Set obj = Retrieval.ExecQuery("Select * From Win32_PingStatus Where Address = '" & Mid(url, 8) & "'")
        For Each OBJStatus In obj
            If IsNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
                Exit Function
            Else
                Exit For '已连接则继续
            End If
        Next
    End If
   
    '通过下载网页头信息获取网络时间
    Set Retrieval = CreateObject("Microsoft.XMLHTTP")
    With Retrieval
        .Open "Get", url, False, "", ""
        .setRequestHeader "If-Modified-Since", "0"
        .setRequestHeader "Cache-Control", "no-cache"
        .setRequestHeader "Connection", "close"
        .Send
        If .Readystate <> 4 Then Exit Function
        GetText = .getAllResponseHeaders()
        i = InStr(1, GetText, "date:", vbTextCompare)
        If i > 0 Then '网页下载成功
            i = InStr(i, GetText, ",", vbTextCompare)
            GetText = Trim(Mid(GetText, i + 1))
             i = InStr(1, GetText, " GMT", vbTextCompare)
            GetText = Left(GetText, i - 1)
            'MsgBox "网络时间:" & GetText
            GetNetTime = GetText
        End If
    End With
    Set Retrieval = Nothing
    Set OBJStatus = Nothing
    Set obj = Nothing
End Function

评分

参与人数 1明经币 +1 收起 理由
xiaxiang + 1 感谢分享

查看全部评分

发表于 2012-8-23 18:01:11 | 显示全部楼层
发表于 2012-8-23 20:38:47 来自手机 | 显示全部楼层
革天明 发表于 2012-8-23 18:01
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=57202
感谢tcsl9621 大师

感谢分享!
发表于 2012-8-23 23:09:41 | 显示全部楼层
我最想实现的就是LISP调用VB界面,调用DLL
发表于 2012-8-24 08:51:47 | 显示全部楼层
革天明 发表于 2012-8-23 23:09
我最想实现的就是LISP调用VB界面,调用DLL

调用VB界面好像猫给过实例的。。。
发表于 2012-8-28 09:11:12 | 显示全部楼层
好东西啊,学习一下~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-6-8 07:41 , Processed in 0.162416 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表