sharp-chat/SharpChatCommon/SharpId.cs

17 lines
440 B
C#
Raw Normal View History

2023-02-08 03:32:12 +00:00
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;
}
2023-02-08 03:32:12 +00:00
}
}