vb.net取网络时间的简单介绍

vb.net获取网络时间失败是不是另一台电脑是vista 及以上版本的系统 ?
用管理员模式 。试试
VB如何“简单”获取网络时间?高手过来支两招 。最简单的办法是用Shell调用NETTIME//servername命令获得时间,你可以将输出重定向到一个文件,然后在VB读取这个文件以获得时间 。---------------------------------------或者服务器上有SQL服务的话,可以:Set DbC = New ADODB.Connection
Dim adoDateTime As New ADODB.Recordset'获取NT-SERVER时间
With DbC
If .State = adStateOpen Then .Close
.CursorLocation = adUseClient
.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER="Server";UID="uID";PWD="uPassword";DATABASE="MyDatabase";OPTION=1 + 2 + 8 + 32 + 2048 + 163841"
.ConnectionTimeout = 90
.Open
adoDateTime.Open "select now() as mysqlTime"
End With ————————————————————————————————————————————使用WindowsAPI的NetRemoteTOD函数获得服务器的时间OptionExplicit
PrivateDeclareFunctionNetRemoteTODLib"Netapi32.dll"(_
tServerAsAny,pBufferAsLong)AsLong
PrivateTypeSYSTEMTIME
wYearAsInteger
wMonthAsInteger
wDayOfWeekAsInteger
wDayAsInteger
wHourAsInteger
wMinuteAsInteger
wSecondAsInteger
wMillisecondsAsInteger
EndType
PrivateTypeTIME_ZONE_INFORMATION
BiasAsLong
StandardName(32)AsInteger
StandardDateAsSYSTEMTIME
StandardBiasAsLong
DaylightName(32)AsInteger
DaylightDateAsSYSTEMTIME
DaylightBiasAsLong
EndType
PrivateDeclareFunctionGetTimeZoneInformationLib"kernel32"(lpTimeZoneInformationAsTIME_ZONE_INFORMATION)AsLong
PrivateDeclareFunctionNetApiBufferFreeLib"Netapi32.dll"(ByVallpBufferAsLong)AsLong
'
PrivateTypeTIME_OF_DAY_INFO
tod_elapsedtAsLong
tod_msecsAsLong
tod_hoursAsLong
tod_minsAsLong
tod_secsAsLong
tod_hundsAsLong
tod_timezoneAsLong
tod_tintervalAsLong
tod_dayAsLong
tod_monthAsLong
tod_yearAsLong
tod_weekdayAsLong
EndType
'
PrivateDeclareSubCopyMemoryLib"kernel32"Alias"RtlMoveMemory"(DestinationAsAny,SourceAsAny,ByValLengthAsLong)
PublicFunctiongetRemoteTOD(ByValstrServerAsString)AsDate
DimresultAsDate
DimlRetAsLong
DimtodAsTIME_OF_DAY_INFO
DimlpbuffAsLong
DimtServer()AsByte
tServer=strServervbNullChar
lRet=NetRemoteTOD(tServer(0),lpbuff)
IflRet=0Then
CopyMemorytod,ByVallpbuff,Len(tod)
NetApiBufferFreelpbuff
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.RaiseNumber:=vbObjectError+1001,_
Description:="cannotgetremoteTOD"
EndIf
EndFunction
'要运行该程序 , 通过如下方式调用 。
【vb.net取网络时间的简单介绍】PrivateSubCommand1_Click()
DimdAsDate
d=getRemoteTOD("\\trademark")
MsgBoxd
EndSub
vb 。net怎么获取网络上的时间 坐等Dim obj,OBJStatus As Object,url As String,GetText As String,i As Integer
Dim Retrieval
url=""
'判断网络是否连接
If url""Then
Retrieval=GetObject("winmgmts:\\.\root\cimv2")
obj=Retrieval.ExecQuery("Select*FromWin32_PingStatusWhereAddress='"Mid(url,8)"'")
For Each OBJStatus In obj
If IsNothing(OBJStatus.StatusCode) Or OBJStatus.StatusCode0 Then
Exit Sub
Else
Exit For'已连接则继续
End If
Next
End If
'通过下载网页头信息获取网络时间
Retrieval=CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open ( "Get",url,False,"","")

推荐阅读