How to Generate Unique Number of 8 digits?

后端 未结 9 930
庸人自扰
庸人自扰 2020-12-30 01:39

I am using this code to generate a 8 digit unique number.

byte[] buffer = Guid.NewGuid().ToByteArray();
return BitConverter.ToUInt32(buffer, 8).ToString();
<         


        
9条回答
  •  有刺的猬
    2020-12-30 01:55

    If you express the no as a combination of day( 2digit), hour(2digit), minute(2digit), second(2digit) and year ( 4 digit) , then it will be 12 digit but always unique no.

     DateTime _now = DateTime.Now;
     string _dd = _now.ToString("dd"); //
     string _mm = _now.ToString("MM");
     string _yy = _now.ToString("yyyy");
     string _hh = _now.Hour.ToString();
     string _min = _now.Minute.ToString();
     string _ss = _now.Second.ToString();
    
     string _uniqueId= _dd+ _hh+ _mm+_min+_ss + _yy;
    

提交回复
热议问题