本文介绍了请帮我生成号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想生成看起来像20100000000001和
的数字 每次增加一个类似于20100000000002的值,因此继续
每次执行每次加1,并且仅更改年度收益,它认为2010年是这一年,并且每年都在变化,
从头再来20110000000001
谢谢您的配合.
I want to generate numbers that look like 20100000000001 and
increasing each time by one that looks like 20100000000002 and so continue
every time up by one at each execution, and only change in the year gain, where it think 2010 is the year and changes each year new and
start all over again 20110000000001
thank you for your cooperation
推荐答案
public class MyPointlessClass
{
DateTime lastTime = new DateTime(0);
Int64 myNumber = 0;
// as a string
private string UpdateRunCount()
{
DateTime now = DateTime.Now;
if (now.Year != lastTime.Year)
{
myNumber = 1;
}
string number = string.Format("{0}{1:0000000000}", now.ToString("yyyy"), myNumber);
lastTime =
return number;
}
// as a numeric value
private Int64 UpdateRunCount()
{
DateTime now = DateTime.Now;
if (now.Year != lastTime.Year)
{
myNumber = 1;
}
Int64 number = (now.Year * 10000000000) + myNumber;
return number;
}
}
这篇关于请帮我生成号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!