2009-08-29 2 views
1

저는 C# win 응용 프로그램에 두 monthcalender가 있습니다. 그 사이의 기간을 계산해야합니다. C#에서 두 monthcalender 사이의 기간을 계산하십시오.

나는 내가 필요로 얼마나 많은 일 두 세 달 또한 년

사이에 필요한 몇 달 견인 다른 세 사이.

내가 사용하는 경우 :

monthcalender.selectstart.month을;

이 명령은 같은 해에 다른 달을 계산하지만, 내년으로 이동할 때는 음수가됩니다. 일

와 같은, 내가 사용

monthcalender.selectstart.dayofyear을;

답변

4

monthcalendar.SelectionStart는 계산할 수있는 DateTime 구조입니다. 두 개의 날짜를 빼면 TimeSpan 구조가되며,이 구조에는 사용자에게 유용한 다양한 속성이 있습니다. 하지만 방정식에서 월의 일을 떠날 것이다

DateTime d1 = calendar1.SelectionStart; 
DateTime d2 = calendar2.SelectionStart; 
ints monthsBetween = d1.Month + d1.Year * 12 - d2.Month - d2.Year * 12; 

: 당신이 DateTime의 달 속성을 사용하고 싶다면

TimeSpan timeBetween = calendar1.SelectionStart - calendar2.SelectionStart; 
MessageBox.Show("Days between dates: " + timeBetween.TotalDays); 

, 당신은 뭔가를 할 수 있습니다.