我尝试将特定格式的字符串转换为TDateTime
使用 C++Builder 2009:
TDateTime dt, dt2;
TFormatSettings FS, FS2;
UnicodeString datestring = "17/10/2017 13:24:33";
UnicodeString datestring2 = "2017.17.10 13:24:33";
FS.DateSeparator = '/';
FS.ShortDateFormat = "dd/mm/yyyy";
FS.LongTimeFormat = "hh:nn:ss";
FS.TimeSeparator = ':';
FS2.DateSeparator = '.';
FS2.ShortDateFormat = "yyyy.dd.mm";
FS2.LongTimeFormat = "hh:nn:ss";
FS2.TimeSeparator = ':';
try{
dt = StrToDateTime(datestring, FS);
dt2 = StrToDateTime(datestring2,FS2);
}catch(EConvertError& e)
{
int a = 2;
}
转换dt
没问题,但转换dt2
抛出异常:
''2017.17.10 13:24:33'' 不是有效的日期和时间