- TimeToStr - C++ Builder
- C++ Builder 的字符串类型、字符类型、字符编码
- TInterfacedPersistent::AfterCons
- TInterfacedPersistent::QueryInte
- TInterfacedPersistent::~TInterfa
- TInterfacedPersistent::TInterfac
- TThread::NameThreadForDebugging
- TThread::Suspended - C++ Builder
- TThread::Terminate - C++ Builder
- TInterfacedObject - C++ Builder
C++ Builder 参考手册 ➙ System::Sysutils ➙ TimeToStr
日期时间类型数值转字符串
头文件:#include <System.SysUtils.hpp>
命名空间:System::Sysutils
函数原型:
System::UnicodeString __fastcall TimeToStr(const System::TDateTime DateTime);
System::UnicodeString __fastcall TimeToStr(const System::TDateTime DateTime, const TFormatSettings &AFormatSettings);
参数:
- DateTime:日期时间类型变量;
- AFormatSettings:地区格式;
返回值:
- 参数 DateTime 转为字符串;
- 没有 AFormatSettings 参数的函数使用全局变量 System::Sysutils::FormatSettings 的格式,函数使用全局变量 FormatSettings 或参数 AFormatSettings 的 LongTimeFormat 成员作为转换的格式,格式的详细说明请参考 FormatDateTime;
- 没有 AFormatSettings 参数的函数不是线程安全的,因为使用了全局变量作为默认的地区格式;带有 AFormatSettings 参数的函数是线程安全的。
例:测试全局变量 FormatSettings 和参数 AFormatSettings 对转换结果的影响
void __fastcall TForm1::Button1Click(TObject *Sender)
{
System::TDateTime dt = Sysutils::Now(); // 当前系统时间
Memo1->Lines->Add(Sysutils::TimeToStr(dt)); // 默认的,使用全局变量格式
TFormatSettings fs = TFormatSettings::Create(L"en_US"); // 美国
Memo1->Lines->Add(Sysutils::TimeToStr(dt,fs)); // 使用美国格式
FormatSettings.LongTimeFormat = L"hh:nn:ss.zzz"; // 修改全局变量格式
Memo1->Lines->Add(Sysutils::TimeToStr(dt)); // 使用全局变量格式
Sysutils::GetFormatSettings(); // 全局变量格式恢复默认为本地格式
Memo1->Lines->Add(Sysutils::TimeToStr(dt)); // 使用全局变量格式
}
运行结果:
![](https://img.haomeiwen.com/i19822773/34cf3f6e18b1a22d.png)
相关:
- 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::Dateutils
- System::TDateTime
- System
C++ Builder 参考手册 ➙ System::Sysutils ➙ TimeToStr
网友评论