重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
还要设置Format 为 : Custom
成都创新互联公司是少有的成都网站制作、成都网站建设、营销型企业网站、微信平台小程序开发、手机APP,开发、制作、设计、买友情链接、推广优化一站式服务网络公司,成立于2013年,坚持透明化,价格低,无套路经营理念。让网页惊喜每一位访客多年来深受用户好评
用的时候用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都是日文的,注释的东西我删除了,主要看代码就好了
这段代码你可以建一个空的解决方案,完全复制到里面去
如控件自身无法设置滚动条,那就在父容器控件中(如FORM)使用滚动条解决问题。另外,也可将日期控件放在弹出窗口中,
TextBox12.Text = DateTimePicker1.Value.ToString("yyyy/MM/dd")
这样格式化一下就可以了
这个控件允许你选择日期和时间;同时,由于这个控件允许你限制输入内容,你可以忽略合法的日期格式。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年开始涉足技术领域。 查看本文国际来源
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#) '还有几(整)秒