C# 求 200709 到 200804 一段数 (顶者有分)

AA 2008-07-01 10:44:54
C# 求 200709 到 200804 一段数 (顶者有分)

比如用户输入 : 200709 200804
求出结果:
200709
2007010
2007011
。。。。

。。。

200803
200804


求出 200709到200804的所有数


...全文
101 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
沧海桑田 2008-07-01
  • 打赏
  • 举报
回复
//把它当作时间来处理应该没有什么问题
//str1,str2分别是输入两个值
DateTime dateTime1=DateTime.ParseExact(str1,"yyyyMM",null);
int year1=dateTime1.year;
int month1=dateTime1.month;
DateTime dateTime2=DateTime.ParseExact(str2,"yyyyMM",null);
int year2=dateTime2.year;
int month2=dateTime2.month;
for(int i=year1;i<year2;i++)
for(int j=1;j<12;j++)
Console.WriteLine(i.toString()+j.toString());
for(int k=1;k<month2;k++)
Console.WriteLine(year2.toString()+k.toString());
//ok



wangping_li 2008-07-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jzywh 的回复:]
C# code

DateTime start = new DateTime(2007, 9, 1);
DateTime end = new DateTime(2008, 4, 1);
DateTime current = start;

while (current <= end)
{
System.Console.WriteLine(current.ToString("yyyyMM"));
current = current.AddMonths(1);
}
[/Quote]
AA 2008-07-01
  • 打赏
  • 举报
回复
good thanks。。。


马上揭帖 。。。
正宗熊猫哥 2008-07-01
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 chinahnzl 的回复:]
我晕。。

我以为你是要找到在这个区间的记录呢。。

楼的各位都行。。
[/Quote]
jzywh 2008-07-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jzywh 的回复:]
C# code

DateTime start = new DateTime(2007, 9, 1);
DateTime end = new DateTime(2008, 4, 1);
DateTime current = start;

while (current <= end)
{
System.Console.WriteLine(current.ToString("yyyyMM"));
current = current.AddMonths(1);
}
[/Quote]

我的输出市这个阿...
200709
200710
200711
200712
200801
200802
200803
200804
正宗熊猫哥 2008-07-01
  • 打赏
  • 举报
回复
先顶再看!!!!!11
chinahnzl 2008-07-01
  • 打赏
  • 举报
回复
我晕。。

我以为你是要找到在这个区间的记录呢。。

楼的各位都行。。
mengxj85 2008-07-01
  • 打赏
  • 举报
回复
自己写一个函数吧,像8楼一样
xhan2000 2008-07-01
  • 打赏
  • 举报
回复
算法问题

string str1 = "200709";
string str2 = "200804";

int x1 = int.parse(str1.substring(0,4));
int x2 = int.parse(str1.substring(5));

int y1 = int.parse(str2.substring(0,4));
int y2 = int.parse(str2.substring(5));

ArrayList al=new ArrayList();

for(int i=x1;i<=y1;i++)
{
if(x1==y1)
{
for(int j=x2;j<=y2;j++){al.Add(i.tostring()+"0"+j}
}else if(i==x1)
{
for(int j=x2;j<=12;j++){al.Add(i.tostring()+"0"+j}
}else if(i==y1)
{
for(int j=1;j<=y2;j++){al.Add(i.tostring()+"0"+j}
}else
{
for(int j=1;j<=12;j++){al.Add(i.tostring()+"0"+j}
}
}
jinjazz 2008-07-01
  • 打赏
  • 举报
回复
动动脑子

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication29
{
class Program
{
static void Main(string[] args)
{
int m1 =200709;
int m2 =200804;

while (m1 <= m2)
{
Console.WriteLine(m1);
if (m1 % 12 == 0)
m1 = m1 + 100-11;
else
m1++;
}

Console.Read();

}

}
}
AA 2008-07-01
  • 打赏
  • 举报
回复
我需要的结果是:
200709
200710
200711
200712
200801
200802
200803
200804

怎么得到这个结果 ??

小弟却是不懂。。
烈火焚身 2008-07-01
  • 打赏
  • 举报
回复
应该不难吧
jzywh 2008-07-01
  • 打赏
  • 举报
回复


DateTime start = new DateTime(2007, 9, 1);
DateTime end = new DateTime(2008, 4, 1);
DateTime current = start;

while (current <= end)
{
System.Console.WriteLine(current.ToString("yyyyMM"));
current = current.AddMonths(1);
}
chinahnzl 2008-07-01
  • 打赏
  • 举报
回复
看你的数字序列。。都是规则的啊。。

200803 不管用什么。。都是小于 200804的。。

这样子还不明白啊?
AA 2008-07-01
  • 打赏
  • 举报
回复
具体点 ?
AA 2008-07-01
  • 打赏
  • 举报
回复
C# 求 200709 到 200804 一段数 (顶者有分)

比如用户输入 : 200709 200804
求出结果:
200709
200710
200711
。。。。

。。。

200803
200804


应该是这样的。。。
上面写错啦。。。

求解。。。
chinahnzl 2008-07-01
  • 打赏
  • 举报
回复
就直接

>=200709 <=200804就行了。。

用字符串型就是了。。

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧