How to get only the date value from a Windows Forms DateTimePicker control?

前端 未结 9 1570
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 03:21

I\'m building an application with C# code.
How do I get only the date value from a DateTimePicker control?

相关标签:
9条回答
  • 2021-01-30 03:38

    You mean how to get date without the time component? Use DateTimePicker.Value.Date But you need to format the output to your needs.

    0 讨论(0)
  • 2021-01-30 03:42
    Datum = DateTime.Parse(DateTimePicker1.Value.ToString("dd/MM/yyyy"))
    
    0 讨论(0)
  • 2021-01-30 03:49

    @Shoban It looks like the question is tagged c# so here is the appropriate snipped http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.value.aspx

    public MyClass()
    {
        // Create a new DateTimePicker
        DateTimePicker dateTimePicker1 = new DateTimePicker();
        Controls.Add(dateTimePicker1);
        MessageBox.Show(dateTimePicker1.Value.ToString());
    
        dateTimePicker1.Value = DateTime.Now.AddDays(1);
        MessageBox.Show(dateTimePicker1.Value.ToString());
     } 
    
    0 讨论(0)
提交回复
热议问题