lrh3321
2016-10-14 14:28:08 +08:00
我尽力了
var aaa =ClassA.yeast();
```csharp
static class ClassA
{
static char[] alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".ToCharArray();
static int length = 64, seed = 0, i = 0;
static string prev = null;
public static string encode(long num) {
var encoded = "";
do {
encoded = alphabet[num % length] + encoded;
num = (int)(num / length) ;
} while (num > 0);
return encoded;
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public static long GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return (long)ts.TotalMilliseconds;
}
public static string yeast() {
var now = encode(GetTimeStamp());
if (now != prev){
seed = 0;
return prev = now;
}
return now + "." + encode(seed++);
}
}
```