DateTimeExtendGetDateTime Method

依格式取得日期

Definition

Namespace: eBizprise.Framework
Assembly: eBizprise.Framework.DatetimeHelper (in eBizprise.Framework.DatetimeHelper.dll) Version: 25.0.0.0+adf38c4ccb2bf98d8ad258a6278302b5e05a94ed
C#
public static DateTime? GetDateTime(
	this string dateTimeString,
	string format
)

Parameters

dateTimeString  String
string擴充屬性
format  String

格式字串;依原定義之格式化字串擴充:

CY:民國年

Return Value

NullableDateTime
DateTime?

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

取來源字串依指定格式轉換為日期格式後回傳。無法正確轉換時回傳null

Example

C#
DateTime dateTime = "2020/01/01 09:00:00".GetDateTime("yyyy/MM/dd HH:mm:ss");
DateTime chineseDateTime = "109/01/01 09:00:00".GetDateTime("CY/MM/dd HH:mm:ss");

Revision History

DateVersionDescription
2020/02/071.0.0.0初版
2025/09/1925.0.0.0彙整2025年度初版

See Also