namespace DS.Module.Core.Extensions; public static class DateTimeExtension { /// /// 时间戳起始日期 /// public static readonly DateTime TimestampStart = new(1970, 1, 1, 0, 0, 0, 0); /// /// 转换为时间戳 /// /// /// 是否使用毫秒 /// public static long ToTimestamp(this DateTime dateTime, bool milliseconds = false) { var timestamp = dateTime.ToUniversalTime() - TimestampStart; return (long)(milliseconds ? timestamp.TotalMilliseconds : timestamp.TotalSeconds); } /// /// 获取周几 /// /// /// public static string GetWeekName(this DateTime datetime) { var day = (int)datetime.DayOfWeek; var week = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" }; return week[day]; } }