DateTimeToStr - C++ Builder

C++ Builder 参考手册 ➙ System::Sysutils ➙ DateTimeToStr


日期时间类型数值转字符串

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

System::UnicodeString __fastcall DateTimeToStr(const System::TDateTime DateTime);
System::UnicodeString __fastcall DateTimeToStr(const System::TDateTime DateTime, const TFormatSettings &AFormatSettings);

参数:

  • DateTime:日期时间类型变量;
  • AFormatSettings:地区格式;

返回值:

  • 参数 DateTime 转为字符串;
  • 可以使用全局变量 System::Sysutils::FormatSettings 修改默认的格式;
  • 只有一个 DateTime 参数的 DateTimeToStr 函数不是线程安全的,因为使用了全局变量作为默认的地区格式;带有 AFormatSettings 参数的函数是线程安全的。

例:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    System::TDateTime dt = Sysutils::Now();
    Memo1->Lines->Add(Sysutils::DateTimeToStr(dt));
    Memo1->Lines->Add(Sysutils::DateTimeToStr(dt,TFormatSettings::Create(L"en_US")));
}

运行结果:

运行结果

相关:

  • System::Sysutils::FormatSettings
  • System::Sysutils::TFormatSettings
  • System::Sysutils::StrToBool
  • System::Sysutils::StrToBoolDef
  • System::Sysutils::TryStrToBool
  • System::Sysutils::BoolToStr
  • System::Sysutils::CurrToStr
  • System::Sysutils::CurrToStrF
  • System::Sysutils::DateTimeToStr
  • System::Sysutils::DateTimeToString
  • System::Sysutils::DateToStr
  • System::Sysutils::FloatToStr
  • System::Sysutils::FloatToStrF
  • System::Sysutils::GUIDToString
  • System::Sysutils::IntToStr
  • System::Sysutils::IntToHex
  • System::Sysutils::TimeToStr
  • System::Sysutils::UIntToStr
  • System::Sysutils
  • System::Currency
  • System
  • std::itoa, std::_itoa, std::_itot, std::_itow
  • std::ltoa, std::_ltoa, std::_ltot, std::_ltow
  • std::ultoa, std::_ultoa, std::_ultot, std::_ultow
  • std::_i64toa, std::_i64tot, std::_i64tow
  • std::_ui64toa, std::_ui64tot, std::_ui64tow
  • std::ecvt, std::_ecvt
  • std::fcvt, std::_fcvt
  • std::gcvt, std::_gcvt
  • <cstdlib>

C++ Builder 参考手册 ➙ System::Sysutils ➙ DateTimeToStr

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容