
正文
vb.net时间同步显示的简单介绍
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
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
相关问答
Q1: 怎么在VB.net中实时显示时间
定时器中处理
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 10 '10毫秒刷新一次
Timer1.Start() '开启定时器
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Now
End Sub
Q2: VB显示当前时间的程序
加入以下代码vb.net时间同步显示:
Private Sub Form_Load()
Text1.Text = Now
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Text1.Text = Now
End Sub
扩展资料:
VB获取系统当前时间并格式化输出
用到vb.net时间同步显示的函数:
Date函数:返回系统vb.net时间同步显示的日期
Now函数:返回系统vb.net时间同步显示的日期和时间
Format函数:根据格式表达式来格式化数据
实例:
Private Sub Form_Load()
'设置同步时间显示
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Format(Now, "hh:mm:ss") '获取当前时间
Label4.Caption = Format(Now, "yyyy-mm-dd") '获取当前日期
Label6.Caption = Format(Now, "yyyy-mm-dd hh:mm:ss") '日期和时间
End Sub
Q3: 怎么用vb.net实现点击按钮显示时间
设计界面双击那个按钮(自动跳到代码里)
然后输入 要显示时间的那个Label.Text = DateTime.Now.ToString()
Q4: 用VB编写局域网时间同步程序
转贴:
获得局域网内指定计算机的时间
我记得有网友问过如何获得局域网上服务器或其它计算机的时间,确实在一个应用系统中保持各客户端的时间一致是非常重要的,我们可 以在客户端程序中通过NetRemoteTOD函数获得局域网内指定计算机的时间(例如以该机时间作为大家时间同步的基准),然 后再以此时间设置本机时间,就可以保持各客户端的时间一致性。下面的代码就是1个通过指定计算机网络名或IP地址获得该机时间的 VB程序:
Option Explicit
'通过NetBIOS的netapi32.dll中的API函数NetRemoteTOD
'获得局域网内指定计算机的时间
'在FORM1中添加1个TEXT1和Command1控件
'将下列代码剪贴到代码窗体即可
Private Const NERR_SUCCESS = 0
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 Function NetRemoteTOD Lib "netapi32" _
(UncServerName As Byte, BufferPtr As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32" _
(ByVal lpBuffer As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Sub Command1_Click()
Dim CPT_Date As TIME_OF_DAY_INFO
Dim Str_Tmp As String
Dim N_Data As Date
CPT_Date = GetRemoteTOD(Text1.Text)
N_Data = DateAdd("s", CPT_Date.tod_elapsedt, #1/1/1970#) '将获得的秒数转换为当前GMT(UTC)时间
N_Data = DateAdd("n", -CPT_Date.tod_timezone, N_Data) '再转化为本地时间(北京时间)
If Text1.Text = "" Then
Str_Tmp = "本机" '若Text1.Text为空,则获得本机时间
Else
Str_Tmp = Text1.Text
End If
Str_Tmp = Str_Tmp "计算机当前时间为:" N_Data
MsgBox Str_Tmp
End Sub
'获得局域网内指定计算机的时间
'CPT_Name为计算机名字,也可以为IP地址,若为空则为本机时间
Private Function GetRemoteTOD(ByVal CPT_Name As String) As TIME_OF_DAY_INFO
Dim bCPT_Name() As Byte
Dim tod As TIME_OF_DAY_INFO
Dim bufptr As Long
CPT_Name = Trim(CPT_Name)
If CPT_Name vbNullChar And CPT_Name "" Then '计算机名不为空
If Left$(CPT_Name, 2) "\" Then
CPT_Name = "\" CPT_Name '计算机名前加2条\
End If
End If
bCPT_Name = CPT_Name vbNullChar
'获得指定计算机的日期时间
If NetRemoteTOD(bCPT_Name(0), bufptr) = NERR_SUCCESS Then
'复制buffer的TIME_OF_DAY_INFO结构数据到tod
CopyMemory tod, ByVal bufptr, LenB(tod)
End If
Call NetApiBufferFree(bufptr) '释放buffer内存
GetRemoteTOD = tod
End Function
Q5: VB怎么设置局域网中其他电脑的时间?
使局域网中vb.net时间同步显示的电脑时间同步方法如下vb.net时间同步显示:
如果使用的是winNT/2000/xpvb.net时间同步显示,设置一台计算机为时间服务器vb.net时间同步显示,
在控制面板中的服务中可以启动或停止。
其他的计算机使用Net
time
命令来进行时间同步。可以做到秒级的时间同步。
NET
TIME
作
用vb.net时间同步显示:使计算机的时钟与另一台计算机或域的时间同步。
命令格式:net
time
[\\computername
|
/domain[:name]]
[/set]
参数介绍:
(1)\\computername要检查或同步的服务器名。
(2)/domain[:name]指定要与其时间同步的域。
(3)/set使本计算机时钟与指定计算机或域的时钟同步。
当然也可以在作为时间服务器的机器上安装GPS。来保证服务器的时间准确。时间服务器也可以选择专业的时间服务器。
关于vb.net时间同步显示和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







