拖一个Timer到你的from里,如果你要一秒种得到4个数,在timer_Tick函数这样写:
string s=System.DateTime.Now.Year.ToString()+System.DateTime.Now.Month.ToString()+System.DateTime.Now.Day.ToString()+System.DateTime.Now.Hour.ToString()+System.DateTime.Now.Minute.ToString()+System.DateTime.Now.Second.ToString();if(this.now_time!=s || this.now_time=="")
{
this.now_time=s; //在类中定义的一个string变量,用来比较
this.NO=0; //在类中定义的一个int变量,用来计数
}
if(this.NO>9)
{this.NO=0}
s+=(this.NO.ToString());
this.NO++;
this.lable.text=s; //如果你要得到一个数字,可以这样写Int64.Parse(s);
string s=System.DateTime.Now.Year.ToString()+System.DateTime.Now.Month.ToString()+System.DateTime.Now.Day.ToString()+System.DateTime.Now.Hour.ToString()+System.DateTime.Now.Minute.ToString()+System.DateTime.Now.Second.ToString();if(this.now_time!=s || this.now_time=="")
{
this.now_time=s; //在类中定义的一个string变量,用来比较
this.NO=0; //在类中定义的一个int变量,用来计数
}
if(this.NO>9)
{this.NO=0}
s+=(this.NO.ToString());
this.NO++;
this.lable.text=s; //如果你要得到一个数字,可以这样写Int64.Parse(s);
然后循环找出里面的数字组成新的字符
为什么要转换成int?
System.Int32
int -2,147,483,648 to 2,147,483,647 Signed 32-bit integer
你要的数字放到int里太大了
这样输出的月份为去掉0得。比如2月就写成2得。需要输出02。时间等也要慢位置输出。
但是这个列的值是唯一的。也就是如果数据库中已经有同样的值。
就需要自增1.耳string 得自增不知道可以否?
String format = "yyyyMMddhhmmss";
System.Console.WriteLine (DateTime.Now.ToString(format));那么有什么办法可一让写入数据库的值唯一呢?
或者遇到不唯一的时后可以自动修改值?(限制在修改最后几位的值)