c/c++

StrToDate - C++ Builder

2022-04-21  本文已影响0人  玄坴

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


字符串转日期类型数值

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

System::TDateTime __fastcall StrToDate(const System::UnicodeString S);
System::TDateTime __fastcall StrToDate(const System::UnicodeString S, const TFormatSettings &AFormatSettings);

参数:

返回值:


例:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ShowDate(StrToDate(L"2022/04/21")); // 中国默认日期格式为 年/月/日

    TFormatSettings fs = TFormatSettings::Create(L"en_US"); // 美国
    ShowDate(StrToDate(L"4/21/2022", fs));                  // 美国默认日期格式为 日/月/年

    Sysutils::FormatSettings.DateSeparator = L'-'; // 把默认的日期分隔符改为减号 '-'
    ShowDate(StrToDate(L"2022-04-21"));            // 默认的日期格式就变成了 年-月-日

    Sysutils::FormatSettings.ShortDateFormat = L"mm/dd/yyyy"; // 继续修改默认日期格式为 日/月/年
    ShowDate(StrToDate(L"04-21-2022"));                       // 这时之前修改的日期分隔符仍然有效,为减号 '-'
}

运行结果:

运行结果

相关:


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

上一篇下一篇

猜你喜欢

热点阅读