简体   繁体   中英

how to insert date & time to DateTimePicker in C#?

i want to insert date & time to DateTimePicker.

for example: date: 03/08/2009 time: 06:45

how i can do it in C# ?

thank's in advance

沿着这条线

myDatePicker.Value = new DateTime(2009, 3, 8, 6, 45, 0);

使用所需的值创建一个新的DateTime并将DateTimePicker的.Value属性设置为该值。

dtp.Value = new DateTime( 2009, 3, 8, 6, 45, 0 );

just want to add, you may also use a string and pass it to the DateTime.Parse method which will return DataTime object as follows, if you have string value representing DateTime in proper format.

So you can avoid splitting your string into values, as Year , Day or Month etc and thereafter passing these values to DateTime Constructor .


Here is how you do it:

dateTimePicker1.Value = DateTime.Parse("03/08/2009 06:45:00"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM