how do i read a time value and then insert it into TimeSpan variables
+1
A:
TimeSpan span = new TimeSpan(days,hours,minutes,seconds,milliseonds);
Or, if you mean DateTime:
DateTime time = new DateTime(year,month,day,minutes,seconds,milliseconds);
Where all of the parameters are ints.
TraumaPony
2008-09-25 07:33:20
A:
You can't change the properties of a TimeSpan. You need to create a new instance and pass the new values there.
jop
2008-09-25 07:34:28
how do i do that @_@
2008-09-25 07:35:44
the other posts have already said it: yourObject.TimeSpan = new TimeSpan(hours, mins, secs);
jop
2008-09-25 07:40:58
+2
A:
From MSDN: A TimeSpan object represents a time interval, or duration of time, measured as a positive or negative number of days, hours, minutes, seconds, and fractions of a second. The largest unit of time used to measure duration is a day.
Here's how you can initialize it to CurrentTime (in ticks):
TimeSpan ts = new TimeSpan(DateTime.Now.Ticks);
Abbas
2008-09-25 07:35:54
+3
A:
If I understand you correctly you're trying to get some user input in the form of "08:00" and want to store the time in a timespan variable?
So.. something like this?
string input = "08:00";
DateTime time;
if (!DateTime.TryParse(input, out time))
{
// invalid input
return;
}
TimeSpan timeSpan = new TimeSpan(time.Hour, time.Minute, time.Second);
VVS
2008-09-25 07:39:45