//生成固定位数的随机数
//ran.Next(999)生成的是1-999的随机数,不能保证位数是固定的。
public static string GenerateOrderNo()
{
Random ran = new Random();
return string.Format("{0}{1}{2:D3}", "用户id", DateTime.Now.ToString("yyyyMMddHHmmss"), ran.Next(999));
// return string.Format("{0}{1}{2:000}", "用户id", DateTime.Now.ToString("yyyyMMddHHmmss"), ran.Next(999));
//日期格式的优化 return string.Format("{0}{1:yyyyMMddHHmmss}{2:000}", "用户id", DateTime.Now, ran.Next(999));
}