i'm trying to convert a string into timeSpan but i can't seem to do it.
i'm using c++ managed code:
TimeSpan timeSpan;
if (TimeSpan::TryParse("01.55", timeSpan))
{
int minute = timeSpan.Minutes;
int hours= timeSpan.Hours;
//do some work here
}
the TryParse is returning flase. what am i doing wrong ?
Thank you,
The time format is wrong, see MSDN TimeSpan::TryParse.
The format should be:
[ws][-]{ d | d.hh:mm[:ss[.ff]] | hh:mm[:ss[.ff]] }[ws]
Or short for your example
1:55
instead of1.55
. This is format for 1 hour and 55 minutes. Your notation is fordays.hours
, which is also wrong as day has only 24 hours so TimeSpan allows max value of 23. Your string still needs:0:0
so it formsdd.hh:mm:ss
to be successfully parsed.