直接上代码,这个小功能没什么好说的
private static long ConvertDateTimeToUnix(DateTime time) { return (time.ToUniversalTime().Ticks - 621355968000000000) / 10000000; }
就这样
这个是转毫秒级Unix
private static long ConvertDateTimeToUnixTicks(DateTime time) { return (long)(time - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalMilliseconds; }