VB有現(xiàn)成的函數(shù):
目前創(chuàng)新互聯(lián)公司已為千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、網(wǎng)站托管維護、企業(yè)網(wǎng)站設(shè)計、寶塔網(wǎng)站維護等服務(wù),公司將堅持客戶導向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
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#) '還有幾(整)秒
還要設(shè)置Format 為 : Custom
用的時候用DateTimePicker1.Text 不要用value
下面是我隨便用了兩個DateTimePicker和一個button一個textbox演示了一下的代碼,你根據(jù)自己的需要調(diào)試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
----------------------------------------------------------
我的操作系統(tǒng)和.net都是日文的,注釋的東西我刪除了,主要看代碼就好了
這段代碼你可以建一個空的解決方案,完全復(fù)制到里面去
CuteEditor 6.0 在線HTML編輯器的領(lǐng)航者
;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 自定義分頁控件
數(shù)據(jù)操作類 Socut.Data.dll for .NET 2.0 v3.1
數(shù)據(jù)操作類 Socut.Data.dll for .NET 1.x v3.1
Developer Express for .NET v7.3.5.0全套完美無限制版
;ID=166512
這個控件允許你選擇日期和時間;同時,由于這個控件允許你限制輸入內(nèi)容,你可以忽略合法的日期格式。DateTimePicker控件類似于MonthView控件,后者允許你選擇一個日期或日期范圍,但不支持時間選擇。在本文中,我將創(chuàng)建一個使用DateTimePicker控件的實例。實例在常用控件(Common Controls)下的工具箱(Toolbox)中找到DateTimePicker控件,并把它添加到Windows Forms中。設(shè)置以下屬性:l Name:dtpDateSelectionl CustomFormat:mm/dd/yyyyl Format:短l MaxDate:12/31/2008l MinDate:01/01/2007l ShowUpDown:假 在Form Load事件中添加以下代碼: dtpDateSelection.Value = Now 創(chuàng)建以下事件: Private Sub dtpDateSelection_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpDateSelection.CloseUp MessageBox.Show(dtpDateSelection.Value) End Sub 結(jié)果在第一個例子中,ShowUpDown屬性設(shè)為假,表示在用戶點擊控件時,控件的日歷部分可見。然后用戶從控件的日歷部分選擇日期。在DateTimePicker控件中選擇一個日期后,你的屏幕看起來與圖A類似。 現(xiàn)在,將ShowUpDown屬性值改為真,再次運行代碼。這次你不會看到控件的日歷部分,你可以點擊控件的上/下箭頭來選擇一個日期。其結(jié)果類似于圖B。 注意,這個控件不允許你選擇小于MinDate屬性值或大于MaxDate屬性值的日期。 更多信息你還可以使用許多其它屬性和重要的方法,讓DateTimePicker控件滿足你的需求。MSDN提供關(guān)于如何使用DateTimePicker控件的其它細節(jié)。 Irina Medvinskaya自1996年開始涉足技術(shù)領(lǐng)域。 查看本文國際來源
這種功能用不到TIMER,TIMER控件用在這種地方也不適合。(假如你所統(tǒng)計的時間很短,在幾分中內(nèi)話,可以使用,假如你統(tǒng)計的時間很長:幾小時、幾天幾夜,建議改用以下方式):
在你需要開始計時的地方加入一個記錄當前時間,在你想結(jié)束的地方也得到一個當前時間。然后將兩個時間相減。
希望以上思路可以幫到你。
Dim?tCount?As?Integer?'用來計數(shù)
Private?Sub?Form1_Load(ByVal?sender?As?System.Object,?ByVal?e?As
System.EventArgs)?Handles?MyBase.Load
tCount?=?10
Timer1.Interval?=?1000?'每秒執(zhí)行一次
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