1、VB怎麼得到區域網中伺服器的時間?
給你一個參考專:屬
http://www.dev-club.com/club/bbs/ShowAnnounce.asp?ID=2134187
2、各位高手vb.net 如何獲取伺服器時間
可以利用後台從伺服器上獲取數據,傳送到前台
3、VB6.0 通過ADO 訪問SQL 資料庫 如何獲取伺服器時間?
select getdate() 伺服器時間
4、vb 獲取 伺服器 日期
Sqlser_time = format(rst(0),"YYYY-MM-DD")
5、VB如何「簡單」獲取網路時間?高手過來支兩招。
最簡單的辦法是用Shell調用NET TIME //<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 ————————————————————————————————————————————使用Windows API的NetRemoteTOD函數獲得伺服器的時間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 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
'
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
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("\\trademark")
MsgBox d
End Sub
6、vb里如何獲取網路時間?
播放MIDE音樂
Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Dim IsMusicOn As Boolean
Dim RetValue As Long
Private Sub Dir1_Change()
File1.Path = Dir1
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1
End Sub
Private Sub File1_DblClick()
Dim fName As String, S As String
fName = File1.Path
If Right(fName, 1) <> "\" Then
fName = fName & "\"
End If
fName = fName & File1.FileName
S = String(LenB(fName), Chr(0))
GetShortPathName fName, S, Len(S)
fName = Left(S, InStr(S, Chr(0)) - 1)
mciSendString "close myMIDI", vbNullString, 0, 0
mciSendString "open" & fName & "alias myMIDI", vbNullString, 0, 0
mciSendString "play myMIDI", vbNullString, 0, 0
End Sub
Private Sub Form_Load()
IsMusicOn = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
IsMusicOn = False
RetValue = mciSendString("CLOSE myMIDI", "", 0, 0)
End Sub
網頁時間3樓正解.
7、vb獲取伺服器時間
日期:DateTime.Now.ToShortDateString時間:DateTime.Now.
8、Vb怎樣讀取SQL伺服器的日期
供參考,VB2005: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Dim datetime As Date conn = New ADODB.Connection conn.ConnectionString = "Provider=SQLOLEDB.1;Password=密碼;Persist Security Info=True;User ID=用戶名;Initial Catalog=資料庫名;Data Source=伺服器IP" conn.Open() rs = New ADODB.Recordset rs.Open("SELECT GETDATE() AS SvrTime", conn, 1, 1) datetime = rs.Fields("SvrTime").Value MsgBox(datetime)'顯示伺服器時間 rs.Close() conn.Close() rs = Nothing conn = Nothing End Sub End Class
9、我想用VB從服務端讀取伺服器端的時間!
我的VB實現
class UDP:
Option Explicit
Public Enum bReceiveAll
OnePacketOnly = False
ReceiveAll = True
End Enum
Private WithEvents WSock As Winsock
Private WithEvents TCounter As Timer
Private m_bError As Boolean
Private m_bReceiveAll As Boolean
Public m_sSendData As String
Public m_sResponse As String
Private Sub TCounter_Timer()
TCounter.Enabled = False
WSock.Close
m_bError = True
End Sub
Private Sub WSock_Close()
WSock.Close
TCounter.Enabled = False
End Sub
Private Sub WSock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
strData = ""
WSock.GetData strData, vbString
m_sResponse = m_sResponse & strData
Select Case m_bReceiveAll
Case True 'Receive All
Case False 'Close when first packet arrived
TCounter.Enabled = False
WSock.Close
m_bError = False
End Select
End Sub
Private Sub WSock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
TCounter.Enabled = False
WSock.Close
m_bError = True
End Sub
Public Sub CloseConnection()
TCounter.Enabled = False
WSock.Close
End Sub
Public Function UDPConnect(ByVal RemoteHost As String, ByVal RemotePort As Long, _
ByVal SendData As String, Optional ByVal LocalPort As Long, _
Optional ByVal ReceiveAll As bReceiveAll = ReceiveAll) As Boolean
m_bReceiveAll = ReceiveAll
m_sSendData = SendData
WSock.RemoteHost = RemoteHost
WSock.RemotePort = RemotePort
If LocalPort <> 0 Then WSock.Bind LocalPort
TCounter.Enabled = True
m_sResponse = ""
WSock.SendData SendData
Do While Not (WSock.State = 0 Or WSock.State = 9)
DoEvents
Loop
UDPConnect = Not m_bError
End Function
Public Sub SetTimerInterval(t As Integer)
TCounter.Interval = t
End Sub
Public Sub Initial(ByRef F As Form, ByRef SockName As String, ByRef TimerName As String)
Set WSock = F.Controls.Add("MSWinsock.Winsock", SockName)
WSock.Protocol = sckUDPProtocol
Set TCounter = F.Controls.Add("VB.Timer", TimerName)
TCounter.Enabled = False
TCounter.Interval = 5000 '預設秒
End Sub
Private Sub Class_Terminate()
On Error Resume Next
WSock.Close
Set TCounter = Nothing
Set WSock = Nothing
End Sub
form:
Dim MyUDP As UDP
Private Sub Command1_Click()
MyUDP.UDPConnect "61.128.128.68", 13, vbCrLf, , OnePacketOnly
MsgBox MyUDP.m_sResponse
End Sub
Private Sub Form_Load()
Set MyUDP = New UDP
MyUDP.Initial Me, "MyUDP", "t"
End Sub
10、vb獲取伺服器時間
在窗體中建一個文本框和時間控制項,可以在文本框中顯示跳動的伺服器時間
Private Sub Form_Load()
Timer1.Interval = 300
End Sub
Private Sub Timer1_Timer()
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
Dim Sqlser_time
cnn.ConnectionString = "driver={SQL Server};" & _
"server=server;uid=sa;pwd=;database=master"
cnn.Open
cmd.ActiveConnection = cnn
cmd.CommandText = "SELECT GETDATE() AS sys_Sqlser_time"
Set rst = cmd.Execute
Sqlser_time = rst(0)
Text1.Text = Sqlser_time
rst.Close
cnn.Close
End Sub