vba - 通过网站获取当前日期/时间
问题描述
通过 Access / VBA 代码我想从世界时间服务器捕获当前日期,如果有人知道方法吗?
解决方案
谢谢,我设法执行。我添加了参考:Microsoft XML,v6.0,并且我能够使用下面的代码成功运行。非常感谢大家。
Public Function DateUtcNow() As Date
' ServiceUrl for time service.
Const ServiceUrl As String = "http://worldclockapi.com/api/json/est/now"
' Engine to communicate with the service.
Dim XmlHttp As XMLHTTP60
Dim ResponseText As String
Dim txdata As Date
On Error GoTo Err_DateUtcNow
Set XmlHttp = New XMLHTTP60
XmlHttp.Open "GET", ServiceUrl, Async
XmlHttp.send
ResponseText = XmlHttp.ResponseText
If Not ResponseText Like "*currentdatetime*" Then txdata = ""
txdata = Mid(ResponseText, InStr(ResponseText, "currentdatetime") + 18, 10)
'MsgBox txdata
MsgBox Format(CDate(txdata), "dd/mm/yyyy")
Exit_DateUtcNow:
Set XmlHttp = Nothing
Exit Function
Err_DateUtcNow:
MsgBox "Error" & Str(Err.Number) & ": " & Err.Description, vbCritical + vbOKOnly, "Web Service Error"
Resume Exit_DateUtcNow
End Function
推荐阅读
- cocos2d-x - cocos2d-x : setCatgoryBitmask 不工作
- javascript - 当确认返回 false 时执行 html 锚点
- angularjs - 如何使用 `ng-repeat` 和 `ng-model` 输入编辑对象属性
- python - 欧几里得距离的矢量化实现
- idris - 是否可以在 Idris 中使模式匹配变得懒惰?
- vba - VBA 可能的重复检查器
- html - CSS底部:0在创建时间线时不起作用?
- javascript - 使用异步执行上下文为 Office.js Javascript Word 加载项添加子例程
- javascript - 根据第一个字符或先前出现的字符限制部分模式
- c# - C# 编译器标志