I am facing problem while converting DataTime into Time on 12 hour clock machine. Following code works fine on 24 Hour clock machine.
(new DisplayReminder(_name, _displayText, _snoozTime, TimeSpan.Parse(_startTime.ToShortTimeString(), CultureInfo.InvariantCulture))).Show();
TimeSpan.Parse(_startTime.ToShortTimeString()
throws exeception that input string not in correct format, here I am trying to get time part from DateTime value _startDate
Any suggestion or solution on this problem.
It's not clear what you're trying to do, but just getting the time of day shouldn't involve string conversions:
TimeSpan time = _stateTime.TimeOfDay;
I'd strongly advise you to avoid string conversions unless they're inherently part of what you're trying to achieve.
Personally I don't like using TimeSpan
as a time of day anyway, but that's the BCL for you. You might want to also look into my Noda Time library which has a clearer separation of various date/time concepts.
See more on this question at Stackoverflow