C++ Builder 參考手冊 ? System::Sysutils ? StrToDateTimeDef
字符串轉日期時間類型數值
頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數原型:
System::TDateTime __fastcall StrToDateTimeDef(
const System::UnicodeString S,
const System::TDateTime Default);
System::TDateTime __fastcall StrToDateTimeDef(
const System::UnicodeString S,
const System::TDateTime Default,
const TFormatSettings &AFormatSettings);
參數:
- S:字符串,日期和時間;
- Default:默認值;
- AFormatSettings:地區格式;
返回值:
- 日期時間類型數值,如果轉換失敗,函數返回參數 Default 值;
- 字符串 S 包含日期和時間,
如果不包含時間,認為是 00:00:00;
如果不包含日期,認為是 1899年12月30日,因為日期是用從這一天開始的天數表示的; - 如果沒有 AFormatSettings 參數,日期格式必須和全局變量 FormatSettings.ShortDateFormat 相同,
日期分隔符必須是 FormatSettings.DateSeparator,
時間可以是12小時或24小時,
時間分隔符必須是 FormatSettings.TimeSeparator,
秒和毫秒之間的小數點必須使用 FormatSettings.DecimalSeparator,
注意這個小數點同時應用在浮點數和貨幣類型的小數點顯示和類型轉換,
上午可以用 "AM" 也可以用 FormatSettings.TimeAMString (在中國為 "上午"),
下午可以用 "PM" 也可以用 FormatSettings.TimePMString (在中國為 "下午"),
如果 FormatSettings 被修改,可以用 Sysutils::GetFormatSettings(); 恢復默認值為本地格式,
請參考本文例子及 StrToTime 的例子; - 如果有 AFormatSettings 參數,日期格式必須和參數 AFormatSettings.ShortDateFormat 相同,
日期分隔符必須是 AFormatSettings.DateSeparator,
時間可以是12小時或24小時,
時間分隔符必須是 AFormatSettings.TimeSeparator,
秒和毫秒之間的小數點必須使用 AFormatSettings.DecimalSeparator
上午可以用 "AM" 也可以用 AFormatSettings.TimeAMString (在中國為 "上午"),
下午可以用 "PM" 也可以用 AFormatSettings.TimePMString (在中國為 "下午"),
請參考本文例子及 StrToTime 的例子; - 日期時間格式可以參考 System::Sysutils::FormatDateTime;
- 函數 StrToDateTime、StrToDateTimeDef 和 TryStrToDateTime 的區別:
? StrToDateTime 轉換失敗拋出異常;
? StrToDateTimeDef 轉換失敗返回默認值;
? TryStrToDateTime 轉換結果通過參數返回,函數返回值返回是否轉換成功; - 沒有 AFormatSettings 參數的 CurrToStrF 函數不是線程安全的,因為使用了全局變量 FormatSettings 作為默認的地區格式;帶有 AFormatSettings 參數的函數是線程安全的。
例:請參考 StrToDateTime、StrToDate 和 StrToDateDef 的例子。
相關:
- System::Sysutils::DateTimeToStr
- System::Sysutils::DateTimeToString
- System::Sysutils::DateToStr
- System::Sysutils::FormatDateTime
- 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::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
- std::atof, std::_ttof, std::_wtof
- std::_atold, std::_ttold, std::_wtold
- std::atoi, std::_ttoi, std::_wtoi
- std::atol, std::_ttol, std::_wtol
- std::atoll, std::_ttoll, std::_wtoll
- std::_atoi64, std::_ttoi64, std::_wtoi64
- std::strtof, std::_tcstof, std::wcstof
- std::strtod, std::_tcstod, std::wcstod
- std::strtold, std::wcstold, std::_strtold, std::_tcstold, std::_wcstold
- std::strtol, std::_tcstol, std::wcstol
- std::strtoll, std::_tcstoll, std::wcstoll
- std::strtoul, std::_tcstoul, std::wcstoul
- std::strtoull, std::_tcstoull, std::wcstoull
- <cstdlib>
C++ Builder 參考手冊 ? System::Sysutils ? StrToDateTimeDef