c# - Addition of times -


i have problem adding times. time addition occur after pm.

i give example.

arrival time | waiting time | departure time | travel time 10:30 pm     | 60           | 11:30 pm       | 0 11:30 pm     | 5            | 11:35 pm       | 5 11:40 pm     | 10           | 11:50 pm       | 10 

the addition goes these formula:

departure time = arrival time + waiting time

next arrival time = departure time + travel time

so problem after addition of 11:50 pm + 10 (min) shows 1.00:20:00 should 12:00 pm

you can use timespan this

//get time part timeofday datetime dt = new datetime(2015, 10, 3, 11, 50, 00); //03/10/2015 11:50:00 var time = dt.timeofday; //11:50:00 //or timespan directly time = new timespan(11, 50, 00); //11:50:00 //add new timespan var nexttime = time.add(new timespan(0, 10, 00)); //12:00:00 

basically, can create instance of timespan specifying hours, minutes, seconds this

timespan ts = new timespan(14, 50, 00); //14:50:00 

in problem, should using datetime variables hold timings, , display time part (maybe). otherwise, when time goes next date, it'll confusing , error prone.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -