첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Program.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 개월 수 구하기 - GetMonthCount(fromDate, toDate)

        /// <summary>
        /// 개월 수 구하기
        /// </summary>
        /// <param name="fromDate">FROM 날짜</param>
        /// <param name="toDate">TO 날짜</param>
        /// <returns>개월 수</returns>
        private static int GetMonthCount(DateTime fromDate, DateTime toDate)
        {
            int month1;
            int month2;

            if(fromDate < toDate)
            {
                month1 = (toDate.Month - fromDate.Month);
                month2 = (toDate.Year  - fromDate.Year ) * 12;
            }
            else
            {
                month1 = (fromDate.Month - toDate.Month);
                month2 = (fromDate.Year  - toDate.Year ) * 12;
            }
            
            return  month1 + month2;
        }

        #endregion
        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            DateTime fromDate = new DateTime(2017, 3, 3);
            DateTime toDate   = new DateTime(2018, 6, 6);

            int monthCount = GetMonthCount(fromDate, toDate);
 
            Console.WriteLine($"FROM 날짜 : {fromDate  }");
            Console.WriteLine($"TO 날짜   : {toDate    }");
            Console.WriteLine($"개월 수   : {monthCount}");
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요