想做一个时间校准的软件,大概思路如下:
客户端调用SQL Server的代码返回当前服务器的时间,请问如何实现?
客户端调用SQL Server的代码返回当前服务器的时间,请问如何实现?
解决方案 »
- 【大散分】拍案惊奇:29年,整整29年!去年的今天...
- 如何在vb6的控件列表中显示listview控件?
- 数学天才请进!
- 救救我!拖动问题
- 通过事件来打开: rst.Open "select * from b", conn, 1, 3 有什么错?
- 注册表操作问题!
- 请问在VB中,如何将10进制转换成16进制?
- 请问怎么样才能禁止在win98中安装程序
- √那位老兄能给我搞到vb的api函数大全,最好包括详细介绍和列子! 谢谢,我能你40分哦!
- 怎么样通过程序在桌面上创建ie的快捷方式。并指定其目标连接
- VB WebBrower如何自动打开外部给的网址链接对应的网页?
- 在WebBrowser中,对网页点击左键,和点右键,如何判断出来?
Option Explicit
Private Declare Function NetRemoteTOD Lib "Netapi32.dll" ( _
tServer As Any, pBuffer As Long) As Long
Private 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 Type
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Private Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Long) As Long
Private Type TIME_OF_DAY_INFO
tod_elapsedt As Long
tod_msecs As Long
tod_hours As Long
tod_mins As Long
tod_secs As Long
tod_hunds As Long
tod_timezone As Long
tod_tinterval As Long
tod_day As Long
tod_month As Long
tod_year As Long
tod_weekday As Long
End Type
Public Function getRemoteTOD(ByVal strServer As String) As Date
Dim result As Date
Dim lRet As Long
Dim tod As TIME_OF_DAY_INFO
Dim lpbuff As Long
Dim tServer() As Byte
tServer = strServer & vbNullChar
lRet = NetRemoteTOD(tServer(0), lpbuff)
If lRet = 0 Then
CopyMemory tod, ByVal lpbuff, Len(tod)
NetApiBufferFree lpbuff
result = DateSerial(tod.tod_year, tod.tod_month, tod.tod_day) + _
TimeSerial(tod.tod_hours, tod.tod_mins - tod.tod_timezone, tod.tod_secs)
getRemoteTOD = result
Else
Err.Raise Number:=vbObjectError + 1001, _
Description:="cannot get remote TOD"
End If
End Function
'要运行该程序,通过如下方式调用。
Private Sub Command1_Click()
Dim d As Date
d = getRemoteTOD("\\192.168.0.12") ''计算机名或IP
' d = getRemoteTOD("\\c1")
MsgBox d
End Sub