如何添加月份和年份 [英] How to add no of months and year

查看:103
本文介绍了如何添加月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个月份的值。然后在sql server中插入语句,所以我不想要月份和年份添加



喜欢

没有月份= 12

年度

201512

201601

201602

201603

201604

201605

201606

201607

201608

201609

201610

201611

解决方案

请查看以下代码:



 使用系统; 

public class 计划
{
public static void Main()
{
int noOfMonth = 5 ;
DateTime currentDate = DateTime.Now;
for int i = 0 ; i < noOfMonth; i ++)
{
Console.WriteLine(currentDate.AddMonths(i).ToString( yyyyMM));
}
}

}





请先问谷歌然后再提出这样的问题。


I have one value no of month.then Insert statment in sql server so i want no of month & year Add

like
no of months = 12
Yearmonth
201512
201601
201602
201603
201604
201605
201606
201607
201608
201609
201610
201611

解决方案

Please check below code:

using System;

public class Program
{
	public static void Main()
	{
		int noOfMonth = 5;
		DateTime currentDate = DateTime.Now;
		for(int i = 0; i < noOfMonth; i++)
		{
   			Console.WriteLine(currentDate.AddMonths(i).ToString("yyyyMM"));
		}
	}

}



Please google first before asking such question.


这篇关于如何添加月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆