导航:首页 > IDC知识 > vb获取服务器时间

vb获取服务器时间

发布时间:2020-12-07 18:55:04

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

与vb获取服务器时间相关的知识