using System.Runtime.CompilerServices; namespace YLErp.Helpers { /// /// 格式化帮助类 /// public static class FormatHelper { /// /// 格式化日期 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Format(DateTime? dt, DateFormatStyle style = DateFormatStyle.yyyyMMdd_dash) { if (dt.HasValue) { switch (style) { case DateFormatStyle.yyyyMMdd_slash: return dt.Value.ToString("yyyy/MM/dd"); default: return dt.Value.ToString("yyyy-MM-dd"); } } return string.Empty; } /// /// 日期格式化(yyyy-MM-dd) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToSqlDate(this DateTime date) { return date.ToString("yyyy-MM-dd"); } /// /// 浮点数格式化 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Format(double? d, string fmt) { return d.HasValue ? d.Value.ToString(fmt) : string.Empty; } /// /// Decimal格式化 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Format(decimal? d, string fmt) { return d.HasValue ? d.Value.ToString(fmt) : string.Empty; } } /// /// 日期格式化样式 /// public enum DateFormatStyle { /// /// yyyy-MM-dd格式 /// yyyyMMdd_dash, /// /// yyyy/MM/dd格式 /// yyyyMMdd_slash, } }