Answer the question
In order to leave comments, you need to log in
Why can't subtract time?
Hello. There is such code -
private DateTime timeStart = DateTime.Now;
private void WorkTime_Tick(object sender, EventArgs e)
{
WorkTimeLabel.Content = "Рабочее время: " + ((DateTime.Now - timeStart).ToString("hh:mm"));
}
System.FormatException: 'The input string was not in the correct format.'
Answer the question
In order to leave comments, you need to log in
Another DateTime.Subtract can be used:
Separators and other "incomprehensible" characters are best escaped (slash, as shown in the example).
If timeStart is earlier by 24 hours, then this information will not be reflected in the hh:mm format. You can use this option:
WorkTimeLabel.Content = "Рабочее время: " +
(DateTime.Now - timeStart).ToString(@"d\д\ hh\:mm").TrimStart('0', 'д').Trim();
TimeSpan
DateTime start = DateTime.Now;
TimeSpan timeDiff = DateTime.Now - start;
timeDiff.Hours;
timeDiff.Minutes;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question