73 lines
1.9 KiB
C#
73 lines
1.9 KiB
C#
using System.Runtime.CompilerServices;
|
|
|
|
namespace YLErp.Helpers
|
|
{
|
|
/// <summary>
|
|
/// 格式化帮助类
|
|
/// </summary>
|
|
public static class FormatHelper
|
|
{
|
|
/// <summary>
|
|
/// 格式化日期
|
|
/// </summary>
|
|
[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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 日期格式化(yyyy-MM-dd)
|
|
/// </summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static string ToSqlDate(this DateTime date)
|
|
{
|
|
return date.ToString("yyyy-MM-dd");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 浮点数格式化
|
|
/// </summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static string Format(double? d, string fmt)
|
|
{
|
|
return d.HasValue ? d.Value.ToString(fmt) : string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Decimal格式化
|
|
/// </summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static string Format(decimal? d, string fmt)
|
|
{
|
|
return d.HasValue ? d.Value.ToString(fmt) : string.Empty;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 日期格式化样式
|
|
/// </summary>
|
|
public enum DateFormatStyle
|
|
{
|
|
/// <summary>
|
|
/// yyyy-MM-dd格式
|
|
/// </summary>
|
|
yyyyMMdd_dash,
|
|
|
|
/// <summary>
|
|
/// yyyy/MM/dd格式
|
|
/// </summary>
|
|
yyyyMMdd_slash,
|
|
}
|
|
}
|