如何在DateTimePicker中选择的Date中添加时间? [英] How to add time in Date which is selected in DateTimePicker?

查看:192
本文介绍了如何在DateTimePicker中选择的Date中添加时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net中创建日期和时间计算器。我想添加在datetimepicker1中选择的Date,Minute,Second in date和其他datetimepicket2中的time。如何增加时间?



例如,



所选日期:13-Mar-14(Datetimepicker1 )

选定时间:上午9:15:00(Datetimepicker2)



现在我要添加24小时30分00秒 (Textbox1,Textbox2,Textbox3)



我的回答将是14-Mar-14 9:45:00



我该怎么办?帮助我....

I am Creating Date & Time Calculator in vb.net. I want to add Hours, Minute, Second in Date which is selected in datetimepicker1 and time which is in in other datetimepicket2. How to add time?

For Example,

Selected Date: 13-Mar-14 (Datetimepicker1)
Selected Time: 9:15:00 AM (Datetimepicker2)

Now I want to add "24 Hours 30 Minute 00 Seconds"(Textbox1, Textbox2, Textbox3)

My Answer Will be "14-Mar-14 9:45:00"

How can I do it? Help me....

推荐答案

请参阅:

DateTime Structure [ ^ ]

特别是 AddDays() AddHours() AddMinutes() AddSeconds()方法,这应该为你带来你完成任务所需的一切。



还有另一种方法可以为DateTime添加东西:它是 TimeSpan ,它包含持续时间的概念,并且本机支持使用DateTime对象的基本算术运算。示例:

Please see:
DateTime Structure[^]
especially the AddDays(), AddHours(), AddMinutes() and AddSeconds() methods, that should bring you everything you need for your task.

There is also another way to add 'something' to a DateTime: it is a TimeSpan, which holds the notion of a duration in time and natively supports basic arithmetic operations with a DateTime object. Example:
DateTime myDate = new DateTime(2014, 3, 7, 11, 12, 00);
TimeSpan ts = TimeSpan.FromHours(1);
myDate += ts; // Here myDate variable will hold the DateTime value 2014, March 7th, 12:12:00





希望这会有所帮助。



Hope this helps.


首先根据您选择的日期和时间创建一个日期,并且添加小时和分钟,它将相应地返回新的日期....





First of all create a date from your selected date and time, and add hours and minutes to it, it will return new date accordingly....


Dim strdatetime As String = String.Format("{0} {1}", "13-Mar-14", "9:15:00 AM")
Dim Date1 As DateTime = Convert.ToDateTime(strdatetime)

Date1 = Date1.AddHours(24).AddMinutes(30)

Dim newdatetime = Date1.ToString()


这篇关于如何在DateTimePicker中选择的Date中添加时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆