C#生成一个几乎不会重复的编号

来源:互联网 发布:尼康优化校准设置技巧 编辑:程序博客网 时间:2024/06/05 19:15
            string No = ""; //生成编号            DateTime now = DateTime.Now;            string Year = now.Year.ToString();            string Month = now.Month<10?"0"+now.Month:now.Month.ToString();            string Day = now.Day < 10 ? "0" + now.Day : now.Day.ToString();            string Hour = now.Hour < 10 ? "0" + now.Hour : now.Hour.ToString();            string Minute = now.Minute < 10 ? "0" + now.Minute : now.Minute.ToString();            string Second = now.Second < 10 ? "0" + now.Second : now.Second.ToString();            string Millisecond = now.Millisecond < 10 ? "0" + now.Millisecond : now.Millisecond.ToString();            Random rd = new Random();            int a = rd.Next(0, 9);            int b = rd.Next(0, 9);            int c = rd.Next(0, 9);            No = Year + Month + Day + Hour + Minute + Second + Millisecond + a + b + c;

原创粉丝点击