增加了新的string.TryToDateTime方法。
This commit is contained in:
parent
785457a5f4
commit
819a5657e8
|
@ -2,8 +2,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace Falcon.SugarApi
|
||||
{
|
||||
|
@ -42,7 +40,6 @@ namespace Falcon.SugarApi
|
|||
public static string[] SplitStr(this string? str,params char[] splitChars)
|
||||
=> str.IsNullOrEmpty() ? Array.Empty<string>() : str.Split(splitChars.Length==0 ? new char[] { ',',',',';',';','.','。' } : splitChars,StringSplitOptions.RemoveEmptyEntries|StringSplitOptions.TrimEntries);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串按格式转换为时间格式
|
||||
/// </summary>
|
||||
|
@ -69,12 +66,22 @@ namespace Falcon.SugarApi
|
|||
try {
|
||||
dt=str.ToDateTime(dateTimeFormat,culture);
|
||||
return true;
|
||||
} catch(Exception) {
|
||||
}
|
||||
catch(Exception) {
|
||||
dt=default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将特定格式字符串转换为DateTime类型
|
||||
/// </summary>
|
||||
/// <param name="str">时间字符串</param>
|
||||
/// <param name="dt">转换后的时间</param>
|
||||
/// <param name="dateTimeFormat">时间格式</param>
|
||||
/// <param name="culture">区域特性.默认CultureInfo.InvariantCulture</param>
|
||||
/// <returns>成功True,失败False</returns>
|
||||
public static bool TryToDateTime(this string str,out DateTime dt,string dateTimeFormat = "",CultureInfo? culture = null)
|
||||
=> str.TryToDateTime(dateTimeFormat,out dt);
|
||||
/// <summary>
|
||||
/// 返回字符串是否为指定格式的日期时间格式
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user