gpt4 book ai didi

delphi日期格式MM|dd|yy转MM/dd/yy错误

转载 作者:行者123 更新时间:2023-12-02 03:34:30 37 4
gpt4 key购买 nike

我需要转换当前日期,其格式为:

     MM|dd|yy     ---  12|09|11

我需要将格式转换为:

     MM/dd/yy     --12/09/11

当前系统日期分隔符是:

   -'|'

我使用的代码为:

  var
sDateOne : TDate ;
begin
Label1.Caption:=datetostr(now); {this display as 12|09|11}
ShortDateFormat:='MM/dd/yy';
DateSeparator:='/';
sDateOne:=StrToDate(Label1.Caption);
FormatDateTime('MM/dd/yy',sDateOne );
Label2.Caption:=datetostr(sDateOne); {this i want as 12/09/11 }
end;

但我在 sDateOne:=StrToDate(Label1.Caption); 行收到错误 enter image description here

请告诉我如何转换日期格式并显示?

最佳答案

这是您的代码的更正版本:

var
DateOne: TDate;
LocalFormatSettings: TFormatSettings;
begin
Label1.Caption := datetostr(now); {this display as 12|09|11}
DateOne := StrToDate(Label1.Caption);
GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, LocalFormatSettings);
LocalFormatSettings.DateSeparator := '/';
Label2.Caption := FormatDateTime('MM/dd/yy', DateOne, LocalFormatSettings); {this i want as 12/09/11 }
end;

有关 GetLocaleFormatSettings 信息,请参阅 http://delphi.about.com/library/rtl/blrtlGetLocaleFormatSettings.htm

关于delphi日期格式MM|dd|yy转MM/dd/yy错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8441443/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com