/// <summary> /// 生成10位时间戳 /// </summary> /// <param name="value">时间</param> /// <returns></returns> public static long GetTimestamp10bit(this DateTime value) { return new DateTimeOffset(value).ToUnixTimeSeconds(); } /// <summary> /// 生成13位时间戳 /// </summary> /// <param name="value">时间</param> /// <returns></returns> public static long GetTimestamp13bit(this DateTime value) { return new DateTimeOffset(value).ToUnixTimeSeconds(); }
//时间戳转换为时间
/// <summary> /// 获取时间 /// </summary> /// <param name="timestamp"></param> /// <returns></returns> public static DateTime GetDateTime(this long timestamp) { long begtime = timestamp * 10000000; DateTime dt_1970 = new DateTime(1970, 1, 1, 0, 0, 0); long tricks_1970 = dt_1970.Ticks;//1970年1月1日刻度 long time_tricks = tricks_1970 + begtime;//日志日期刻度 DateTime dt = new DateTime(time_tricks);//转化为DateTime return dt; }