本文整理自网络,侵删。
今天测试写了很久的模拟期货交易平台这个软件的时候,发现K线中的数据很多都是走错了的。
原因分析
Delphi调试很麻烦,于是打出log来看看,最终发现服务器传过来的数据的日期格式和本机的时间格式不一样,导致在判断时间是否相等的时候出现了错误。所以需要一个函数来判断不同时间格式的时间是否相等。当然服务器的时间格式是固定不变的,服务器的时间格式是"yyyy-mm-dd",本地时间可以是所有时间格式中的任意一种。
代码实现
//判断是否是日期格式字符串
function IsDateStr(Value: String): Boolean;
var
Temp: TDateTime;
begin
Result := TryStrToDate(Value, Temp);
end;
function IsTheSameDate(date1,date2:String):Boolean;
begin
Result := False;
if (date1 = date2) then
begin
Result := True;
end else if (IsDateStr(date1)) then
begin
if (FormatDateTime('yyyy-mm-dd',StrToDate(date1)) = date2) then
begin
Result := True;
end;
end else if (IsDateStr(date2)) then
begin
if (FormatDateTime('yyyy-mm-dd',StrToDate(date2)) = date1) then
begin
Result := True;
end;
end;
end;
相关阅读 >>
Delphi ioutils 单元(5): tdirectory.tdirectory 的其他功能
Delphi 注入不用writeprocessmemory 函数
Delphi clipboard 截图后将图片数据复制到剪贴板
更多相关阅读请进入《Delphi》频道 >>