本文介绍了获取n个月的日期C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人如何获得下个月的日期为10个月或任何月份我尝试但只能让我6个月



什么是正确的句法



我的尝试:



hi every body how to get the dates of next month for 10 months or any number of months i try that but only gets me 6 months

what is the correct syntactics

What I have tried:

var x = 10; // 10months
          for (int i = 0; i < x; i++)
          {
              DateTime sixmonthsfromnow = today.AddMonths(x);
              MessageBox.Show(sixmonthsfromnow.ToShortDateString());
              x--;
          }

推荐答案

StringBuilder str = new StringBuilder();
var x = 10; // 10months
for (int i = 0; i < x; i++)
{
    DateTime sixmonthsfromnow = DateTime.Now.AddMonths(i+6);
    str.AppendLine(sixmonthsfromnow.ToString("yyyy MM dd"));
}
MessageBox.Show(str.ToString());





编辑====== =======



如果您认为我的解决方案非常糟糕,那么如果您将自己的解决方案投票给自己的解决方案。 FFS。



EDIT =============

Whoever voted this a 1 - post your own solution if you think mine is so bad. FFS.


StringBuilder str = new StringBuilder();
          var x = 10; // 10 months total period
          var y = 1; // variable for increase month every one,two ... month
          for (int i = 0; i < x; i++)
          {
              DateTime sixmonthsfromnow = DateTime.Now.AddMonths(i + y);
              str.AppendLine(sixmonthsfromnow.ToString("yyyy/MM/dd"));
          }
          MessageBox.Show(str.ToString());


这篇关于获取n个月的日期C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:45