C++ Builder 參考手冊 ? System::Sysutils ? TryStrToDate
字符串轉(zhuǎn)日期類型數(shù)值
頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:
bool __fastcall TryStrToDate(
const System::UnicodeString S,
System::TDateTime &Value);
bool __fastcall TryStrToDate(
const System::UnicodeString S,
System::TDateTime &Value,
const TFormatSettings &AFormatSettings);
參數(shù):
- S:字符串;
- Value:返回日期類型數(shù)值轉(zhuǎn)換結果;
- AFormatSettings:地區(qū)格式;
返回值:
- true:通過參數(shù) Value 返回日期時間類型數(shù)值,
- false:轉(zhuǎn)換失敗;
- 字符串 S 必須是日期,不能包含時間;
- 如果沒有 AFormatSettings 參數(shù),日期格式必須和全局變量 FormatSettings.ShortDateFormat 相同,分隔符必須是 FormatSettings.DateSeparator,請參考本文例子;
如果有 AFormatSettings 參數(shù),日期格式必須和參數(shù) AFormatSettings.ShortDateFormat 相同,分隔符必須是 AFormatSettings.DateSeparator,請參考 StrToDate 的例子; - 日期時間格式可以參考 System::Sysutils::FormatDateTime;
- 函數(shù) StrToDate、StrToDateDef 和 TryStrToDate 的區(qū)別:
? StrToDate 轉(zhuǎn)換失敗拋出 EConvertError 異常;
? StrToDateDef 轉(zhuǎn)換失敗返回默認值;
? TryStrToDate 轉(zhuǎn)換結果通過參數(shù)返回,函數(shù)返回值返回是否轉(zhuǎn)換成功; - 沒有 AFormatSettings 參數(shù)的函數(shù)不是線程安全的,因為使用了全局變量 FormatSettings 作為默認的地區(qū)格式;帶有 AFormatSettings 參數(shù)的函數(shù)是線程安全的。
相關:
- System::Sysutils::DateTimeToStr
- System::Sysutils::DateTimeToString
- System::Sysutils::DateToStr
- System::Sysutils::FormatDateTime
- System::Sysutils::FormatSettings
- System::Sysutils::GetFormatSettings
- System::Sysutils::StrToBool
- System::Sysutils::StrToBoolDef
- System::Sysutils::StrToCurr
- System::Sysutils::StrToCurrDef
- System::Sysutils::StrToDate
- System::Sysutils::StrToDateDef
- System::Sysutils::StrToDateTime
- System::Sysutils::StrToDateTimeDef
- System::Sysutils::StrToFloat
- System::Sysutils::StrToFloatDef
- System::Sysutils::StrToInt
- System::Sysutils::StrToIntDef
- System::Sysutils::StrToInt64
- System::Sysutils::StrToInt64Def
- System::Sysutils::StrToTime
- System::Sysutils::StrToTimeDef
- System::Sysutils::StrToUInt
- System::Sysutils::StrToUIntDef
- System::Sysutils::StrToUInt64
- System::Sysutils::StrToUInt64Def
- System::Sysutils::TFormatSettings
- System::Sysutils::TimeToStr
- System::Sysutils::TryStrToBool
- System::Sysutils::TryStrToCurr
- System::Sysutils::TryStrToDate
- System::Sysutils::TryStrToDateTime
- System::Sysutils::TryStrToFloat
- System::Sysutils::TryStrToInt
- System::Sysutils::TryStrToInt64
- System::Sysutils::TryStrToTime
- System::Sysutils::TryStrToUInt
- System::Sysutils::TryStrToUInt64
- System::Sysutils
- System::TDateTime
- System
C++ Builder 參考手冊 ? System::Sysutils ? TryStrToDate