美文网首页
TryStrToDate - C++ Builder

TryStrToDate - C++ Builder

作者: 玄坴 | 来源:发表于2022-05-24 14:35 被阅读0次

C++ Builder 参考手册System::SysutilsTryStrToDate


字符串转日期类型数值

头文件:#include <System.SysUtils.hpp>
命名空间:System::Sysutils
函数原型:

bool __fastcall TryStrToDate(
    const System::UnicodeString S,
    System::TDateTime &Value);

bool __fastcall TryStrToDate(
    const System::UnicodeString S,
    System::TDateTime &Value,
    const TFormatSettings &AFormatSettings);

参数:

  • S:字符串;
  • Value:返回日期类型数值转换结果;
  • AFormatSettings:地区格式;

返回值:

  • true:通过参数 Value 返回日期时间类型数值,
  • false:转换失败;
  • 字符串 S 必须是日期,不能包含时间;
  • 如果没有 AFormatSettings 参数,日期格式必须和全局变量 FormatSettings.ShortDateFormat 相同,分隔符必须是 FormatSettings.DateSeparator,请参考本文例子;
    如果有 AFormatSettings 参数,日期格式必须和参数 AFormatSettings.ShortDateFormat 相同,分隔符必须是 AFormatSettings.DateSeparator,请参考 StrToDate 的例子;
  • 日期时间格式可以参考 System::Sysutils::FormatDateTime
  • 函数 StrToDateStrToDateDef 和 TryStrToDate 的区别:
    StrToDate 转换失败抛出 EConvertError 异常;
    StrToDateDef 转换失败返回默认值;
    • TryStrToDate 转换结果通过参数返回,函数返回值返回是否转换成功;
  • 没有 AFormatSettings 参数的函数不是线程安全的,因为使用了全局变量 FormatSettings 作为默认的地区格式;带有 AFormatSettings 参数的函数是线程安全的。

相关:


C++ Builder 参考手册System::SysutilsTryStrToDate

相关文章

网友评论

      本文标题:TryStrToDate - C++ Builder

      本文链接:https://www.haomeiwen.com/subject/puidahtx.html