sharp-chat/SharpChatCommon/SharpId.cs

16 lines
440 B
C#

using System;
using System.Threading;
namespace SharpChat {
public static class SharpId {
private const long EPOCH = 1588377600000;
private static int Counter = 0;
public static long Next() {
long num = DateTimeOffset.Now.ToUnixTimeMilliseconds() - EPOCH;
num <<= 8;
num |= (ushort)(Interlocked.Increment(ref Counter) & 0xFFFF);
return num;
}
}
}