生成唯一编码

前缀:prefix

public static string NewSequenceNumber(string prefix)
{
      lock (_localObj)
     {
     System.Threading.Thread.Sleep(10); //让进程停止10毫秒
     DateTime d = DateTime.Now;
     Int64 s = ((d.Year-2000) * 366 + d.Month * 31 + d.Day) * 24;
     s = ((s + d.Hour) * 60 + d.Minute)*60;
     s = (s+ d.Second)*1000 + d.Millisecond;
    return prefix +s.ToString();
    }

}

posted @ 2016-10-27 14:45  木木的博客  阅读(1289)  评论(0编辑  收藏  举报