设计一个c#函数实现对序号的自动增加
设计一个c#函数实现对序号的自动增加,数据格式为”TT”+4位年份+2位月份+2位日期+序号,每调用一次,首先分解入口参数,如果入口日期等于当天日期,则返回:”TT”+入...
设计一个c#函数实现对序号的自动增加,数据格式为”TT”+4位年份+2位月份+2位日期+序号,每调用一次,首先分解入口参数,如果入口日期等于当天日期,则返回:”TT”+入口日期(格式:4位年份+2位月份+2位日期)+(序号+1)否则返回:”TT”+当天日期(格式:4位年份+2位月份+2位日期)+0001函数格式:string CreateNext(string XhNow){}例如:当前时间2012年02月05日,调用CreateNext(“TT201202050888”),则应该返回“TT201202050889”再如:当前时间2012年02月05日,调用CreateNext(“TT201101050888”),则应该返回“TT201202050001”要求:必须考虑不足位的填充,例如:月份为1位前面填充1位0,最后的序号是固定4位,不考虑序号超过4位的情况。
展开
2013-08-10
展开全部
string CreateNext(string XhNow)
{
if (XhNow.Length < 14) return string.Empty; // 不足14位的不合法要求,直接返回空值
int xhYear = Convert.ToInt32(XhNow.SubString(2, 4)); // 取得年
int xhMonth = Convert.ToInt32(XhNow.Substring(6, 2)); // 月
int xhDay = Convert.ToInt32(XhNow.Substring(8, 2)); // 日
int count = 0; if (xhYear == DateTime.Now.Year && xhMonth == DateTime.Now.Month && xhDay == DateTime.Now.Day)
{
count = Convert.ToInt32(XhNow.Substring(10));
}
return "TT" + DateTime.Now.ToString("yyyy-MM-dd") + (++count).ToString("0000");
}
{
if (XhNow.Length < 14) return string.Empty; // 不足14位的不合法要求,直接返回空值
int xhYear = Convert.ToInt32(XhNow.SubString(2, 4)); // 取得年
int xhMonth = Convert.ToInt32(XhNow.Substring(6, 2)); // 月
int xhDay = Convert.ToInt32(XhNow.Substring(8, 2)); // 日
int count = 0; if (xhYear == DateTime.Now.Year && xhMonth == DateTime.Now.Month && xhDay == DateTime.Now.Day)
{
count = Convert.ToInt32(XhNow.Substring(10));
}
return "TT" + DateTime.Now.ToString("yyyy-MM-dd") + (++count).ToString("0000");
}
2013-08-10
展开全部
public string CreateNext(string XhNow)
{
string year = DateTime.Now.Year.ToString();
string month = (DateTime.Now.Month < 10 ? "0" : "") + DateTime.Now.Month.ToString();
string day = (DateTime.Now.Day < 10 ? "0" : "") + DateTime.Now.Day.ToString();
string temp=XhNow.Substring(2, XhNow.Length - 6) ;
if (temp == year + month + day)
{
temp =(int.Parse( XhNow.Substring(XhNow.Length - 4, 4).ToString())+1).ToString();
XhNow = XhNow.Substring(0, XhNow.Length - 4);
for (int i = 0; i < 4 - temp.Length; i++)
XhNow = XhNow + "0";
XhNow = XhNow + temp;
}
else XhNow = year + month + day + "0001";
return XhNow;
}
{
string year = DateTime.Now.Year.ToString();
string month = (DateTime.Now.Month < 10 ? "0" : "") + DateTime.Now.Month.ToString();
string day = (DateTime.Now.Day < 10 ? "0" : "") + DateTime.Now.Day.ToString();
string temp=XhNow.Substring(2, XhNow.Length - 6) ;
if (temp == year + month + day)
{
temp =(int.Parse( XhNow.Substring(XhNow.Length - 4, 4).ToString())+1).ToString();
XhNow = XhNow.Substring(0, XhNow.Length - 4);
for (int i = 0; i < 4 - temp.Length; i++)
XhNow = XhNow + "0";
XhNow = XhNow + temp;
}
else XhNow = year + month + day + "0001";
return XhNow;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询