C#日付プラス日数

1004 ワード

        #region        ,              
        /// 
        ///        ,              
        /// 
        /// 
        /// 
        /// 
        public static string ReTime(string data, int str)
        {
            DateTime dt = DateTime.Parse(data);
            int year = dt.Year;
            int month = dt.Month;
            int day = dt.Day;
            int n = DateTime.DaysInMonth(year, month);
            int k = day + str;
            if (k > n)
            {
                day = str - (n - day);
                month = month + 1;
                if (month > 12)
                {
                    month = 1;
                    year = year + 1;
                }
            }
            else
            {
                day = day + str;
            }
            string c = year + "-" + month + "-" + day;
            return c;
        }
        #endregion