0

I have two textboxes in which the user will enter startTime and endTime in 12 hours format (Eg. 10:30 AM to 7:30 PM).

On clicking the Calculate button, the user should get the difference between the two times inputted in textbox.

I have not getting what datatype should handle this inputted text.

I would really appreciate if someone could write few lines of program for me to understand better.

4

2 回答 2

2

我看到你今天加入了,欢迎来到 Stackoverflow。这是您应该尝试的方法:使用解析两个时间DateTime.ParseExact,然后计算它们的差异,例如:

DateTime  dt1 = DateTime.ParseExact("10:30 AM","h:mm tt", CultureInfo.InvariantCulture);
DateTime dt2 = DateTime.ParseExact("7:30 PM", "h:mm tt", CultureInfo.InvariantCulture);
TimeSpan difference = dt2 - dt1;

Console.WriteLine(difference.TotalHours);
Console.WriteLine(difference.TotalMinutes);

你应该把你在你的问题中尝试过的东西以及你困在哪里。您可能会看到http://www.whathaveyoutried.com/

于 2013-05-14T09:34:44.327 回答
0

首先将文本框解析为DateTime调用date1date2使用的值DateTime.ParseExact()

然后使用计算差异TimeSpan delta = date2 - date1;

但是到目前为止,您尝试过什么?在发布到这里之前,你需要付出更多的努力去尝试。

于 2013-05-14T09:28:32.770 回答