十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
VB有现成的函数:
目前创新互联公司已为千余家的企业提供了网站建设、域名、网页空间、网站托管维护、企业网站设计、宝塔网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
DateDiff(格式,日期1,日期2)
如今天到2010-5-1 8:00:00的时间差,代码:
DateDiff("yyyy",Now,#2010-5-1 8:00:00#) '还有几(整)年
DateDiff("q",Now,#2010-5-1 8:00:00#) '还有几(整)季度
DateDiff("m",Now,#2010-5-1 8:00:00#) '还有几(整)月
DateDiff("d",Now,#2010-5-1 8:00:00#) '还有几(整)天
DateDiff("ww",Now,#2010-5-1 8:00:00#) '还有几(整)周
DateDiff("h",Now,#2010-5-1 8:00:00#) '还有几(整)小时
DateDiff("n",Now,#2010-5-1 8:00:00#) '还有几(整)分钟
DateDiff("s",Now,#2010-5-1 8:00:00#) '还有几(整)秒
还要设置Format 为 : Custom
用的时候用DateTimePicker1.Text 不要用value
下面是我随便用了两个DateTimePicker和一个button一个textbox演示了一下的代码,你根据自己的需要调试DateTimePicker风格
------------------------------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
#Region
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents DateTimePicker2 As System.Windows.Forms.DateTimePicker
System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.DateTimePicker2 = New System.Windows.Forms.DateTimePicker
Me.SuspendLayout()
'
'DateTimePicker1
'
Me.DateTimePicker1.AllowDrop = True
Me.DateTimePicker1.CustomFormat = "yyyy-MM-dd"
Me.DateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom
Me.DateTimePicker1.Location = New System.Drawing.Point(56, 24)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.ShowUpDown = True
Me.DateTimePicker1.Size = New System.Drawing.Size(160, 19)
Me.DateTimePicker1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(144, 128)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(136, 72)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = "TextBox1"
'
'DateTimePicker2
'
Me.DateTimePicker2.CustomFormat = "yyyy-MM-dd"
Me.DateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Custom
Me.DateTimePicker2.Location = New System.Drawing.Point(40, 160)
Me.DateTimePicker2.Name = "DateTimePicker2"
Me.DateTimePicker2.Size = New System.Drawing.Size(120, 19)
Me.DateTimePicker2.TabIndex = 3
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.DateTimePicker2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = DateTimePicker1.Text
End Sub
End Class
----------------------------------------------------------
我的操作系统和.net都是日文的,注释的东西我删除了,主要看代码就好了
这段代码你可以建一个空的解决方案,完全复制到里面去
CuteEditor 6.0 在线HTML编辑器的领航者
;ID=144183
ComponentArt.Charting.WebChart.dll
;ID=144386
ComponentArt.Web.UI 2007.2源代码+实例+DLL
ComponentArt.WebUI.2007.1破解DLL
;ID=143055
ComponentArt.WebUI.2007.1源代码
;ID=143224
ComponentArt.Web.UI.2006.2
;ID=143212
ComponentArt.Web.UI.2006.2源代码
;ID=143219
ComponentArt.Web.UI.2006.1
;ID=142983
Infragistics NetAdvantage for ASP.NET 2007 Vol 2
;ID=159861
Infragistics NetAdvantage AppStylist 2007 Vol 2
;ID=159859
Infragistics TestAdvantage WinForms 2007 For CLR2
;ID=159870
Infragistics TestAdvantage WinForms 2007 for CLR1.x
;ID=159868
Infragistics NetAdvantage for Windows Forms 2007 Vol 2
;ID=159863
Infragistics NetAdvantage 2007 for WPF
;ID=159857
Infragistics NetAdvantage 2006 Vol2 CLR1.x
;ID=159814
Infragistics NetAdvantage 2006 Vol2 for CLR2
;ID=159854
Infragistics NetAdvantage 2006 Vol2 CLR1.x
;ID=159814
ComponentOne Studio 2007 v1.5 for ASP.NET 2.0
;ID=159753
ComponentOne Studio 2007 v1.5 for ASP.NET 1.x
;ID=159745
ComponentOne Studio 2006 v2 for ASP.NET 2.0
;ID=159739
ComponentOne Studio 2006 v2 for ASP.NET 1.x
;ID=159734
ComponentOne Studio for Mobile Devices 2007 v1.5 CLR1x
;ID=159812
ComponentOne Studio for Mobile Devices 2006 v2 CLR2
;ID=159811
ComponentOne Studio for Mobile Devices 2006 v2 CLR1.x
;ID=159807
ComponentOne Studio 2007 v1.5 for .NET CLR2
;ID=159802
ComponentOne Studio 2007 v1.5 for .NET CLR1.x
;ID=159798
ComponentOne Studio for .NET 2006 v2 CLR2
;ID=159780
ComponentOne Studio for .NET 2006 v2 CLR1.x
;ID=159777
ComponentOne Studio for ActiveX 2007 v1.5
;ID=159727
ComponentOne Studio for ActiveX 2006 v2 CLR2
;ID=159725
ComponentOne Studio for ActiveX 2006 v2 CLR1.x
;ID=159724
Telerik RadWindow for ASP.NET 2.0 v1.8.2.0
;ID=156136
Telerik RadUpload for ASP.NET 2.0 v2.3.2.0
;ID=156135
Telerik RadTreeView for ASP.NET 2.0 v6.2.2.0
;ID=156134
Telerik RadTabStrip for ASP.NET 2.0 v3.5.2.0
;ID=156132
Telerik RadToolbar for ASP.NET 2.0 v1.5.2.0
;ID=156133
Telerik RadSplitter for ASP.NET 2.0 v1.2.2.1
;ID=156131
Telerik RadSpell for ASP.NET 2.0 v3.1.2.0
;ID=156130
Telerik RadRotator for ASP.NET 2.0 v2.6.2.0
;ID=156129
Telerik RadPanelbar for ASP.NET 2.0 v4.2.2.0
;ID=156128
Telerik RadMenu for ASP.NET 2.0 v4.2.2.0
;ID=156127
Telerik RadInput for ASP.NET 2.0 v2.0.2.0
;ID=156126
Telerik RadGrid for ASP.NET 2.0 v4.6.2.0
;ID=156125
Telerik RadEditor for ASP.NET 2.0 v7.1.2.0
;ID=156124
Telerik RadComboBox for ASP.NET 2.0 v2.7.2.0
;ID=156122
Telerik RadDock for ASP.NET 2.0 v1.8.2.0
;ID=156123
Telerik RadChart for ASP.NET 2.0 v3.2.1.0
;ID=156121
Telerik RadCalendar for ASP.NET 2.0 v2.1.2.0
;ID=156120
Telerik RadAjax for ASP.NET 2.0 v1.7.2.0
;ID=156119
telerik r.a.d.upload
;ID=143044
telerik r.a.d.window
;ID=142980
telerik r.a.d ToolBar
;ID=143077
telerik r.a.d.Chart
;ID=143075
telerik r.a.d.combobox
;ID=143048
DotNetBar for VS2005 6.8.0.1
;ID=144521
DotnetCharting 4.3破解DLL
;ID=144388
DotNET Charting WebForms
;ID=144461
dotnetCharting.WinForms
;ID=144455
TeeChart for .NET 3.2.2763.26084 完美DLL
;ID=165932
TeeChart for .NET 3.2.2699.17379 完美DLL
;ID=165929
Godiagram Web 2.6.2 for .NET 2.0
Godiagram Win 2.6.2 for .NET 2.0
DevExpress 7.3.4 完美破解DLL
;ID=165852
Dxperience 7.3.5 完美破解DLL
;ID=165851
DevExpress.LocalizationCHS.Dll
NickLee.Web.UI
;ID=143052
SolpartWebControls
;ID=142981
AspNetPager 6.0 for ASP.NET 1.x 自定义分页控件
AspNetPager 6.0 for ASP.NET 2.0 自定义分页控件
数据操作类 Socut.Data.dll for .NET 2.0 v3.1
数据操作类 Socut.Data.dll for .NET 1.x v3.1
Developer Express for .NET v7.3.5.0全套完美无限制版
;ID=166512
这个控件允许你选择日期和时间;同时,由于这个控件允许你限制输入内容,你可以忽略合法的日期格式。DateTimePicker控件类似于MonthView控件,后者允许你选择一个日期或日期范围,但不支持时间选择。在本文中,我将创建一个使用DateTimePicker控件的实例。实例在常用控件(Common Controls)下的工具箱(Toolbox)中找到DateTimePicker控件,并把它添加到Windows Forms中。设置以下属性:l Name:dtpDateSelectionl CustomFormat:mm/dd/yyyyl Format:短l MaxDate:12/31/2008l MinDate:01/01/2007l ShowUpDown:假 在Form Load事件中添加以下代码: dtpDateSelection.Value = Now 创建以下事件: Private Sub dtpDateSelection_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpDateSelection.CloseUp MessageBox.Show(dtpDateSelection.Value) End Sub 结果在第一个例子中,ShowUpDown属性设为假,表示在用户点击控件时,控件的日历部分可见。然后用户从控件的日历部分选择日期。在DateTimePicker控件中选择一个日期后,你的屏幕看起来与图A类似。 现在,将ShowUpDown属性值改为真,再次运行代码。这次你不会看到控件的日历部分,你可以点击控件的上/下箭头来选择一个日期。其结果类似于图B。 注意,这个控件不允许你选择小于MinDate属性值或大于MaxDate属性值的日期。 更多信息你还可以使用许多其它属性和重要的方法,让DateTimePicker控件满足你的需求。MSDN提供关于如何使用DateTimePicker控件的其它细节。 Irina Medvinskaya自1996年开始涉足技术领域。 查看本文国际来源
这种功能用不到TIMER,TIMER控件用在这种地方也不适合。(假如你所统计的时间很短,在几分中内话,可以使用,假如你统计的时间很长:几小时、几天几夜,建议改用以下方式):
在你需要开始计时的地方加入一个记录当前时间,在你想结束的地方也得到一个当前时间。然后将两个时间相减。
希望以上思路可以帮到你。
Dim tCount As Integer '用来计数
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
tCount = 10
Timer1.Interval = 1000 '每秒执行一次
Timer1.Enabled = True
End
Sub
Private Sub
Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
tCount -= 1
If tCount = 0 Then
MessageBox.Show("时间到")
Timer1.Enabled = False
End If
End
Sub