procedure TForm1.Button1Click(Sender: TObject); var d:TDateTime; tmp:char; begin tmp :=DateSeparator; DateSeparator :='/'; d := StrToDate('2007/12/31'); ShowMessage(DateToStr(d)); DateSeparator := tmp; end;
先把 2008/5/8 中的 / replace 成 -Replaces all occurrences of a substring with another string.UnitStrUtilsCategorystring handling routinesDelphi syntax:function AnsiReplaceStr(const AText, AFromText, AToText: string): string;C++ syntax:extern PACKAGE AnsiString __fastcall AnsiReplaceStr(const AnsiString AText, const AnsiString AFromText, const AnsiString AToText);DescriptionCall AnsiReplaceStr to scan the string specified by AText and replace all occurrences of the string specified by AFromText with the string specified by AToText. Occurrences of AFromText are identified by a case-sensitive comparison. The identification of substrings is not recursive: if the substitution of AToText results in a new match for AFromText, that match is not replaced.
uses SysUtils;
#include <stdio.h>int main()
{
int a,b,c;
sscanf("2008-5-8","%d%*[-/]%d%*[-/]%d",&a,&b,&c);
printf("%d %d %d\n",a,b,c);
sscanf("2008/5/8","%d%*[-/]%d%*[-/]%d",&a,&b,&c);
printf("%d %d %d\n",a,b,c); return 0;
}
var d:TDateTime;
tmp:char;
begin
tmp :=DateSeparator;
DateSeparator :='/';
d := StrToDate('2007/12/31');
ShowMessage(DateToStr(d));
DateSeparator := tmp;
end;
AFromText, const AnsiString AToText);DescriptionCall AnsiReplaceStr to scan the string specified by AText and replace all occurrences of the string specified by AFromText with the string specified by AToText. Occurrences of AFromText are identified by a case-sensitive comparison. The identification of substrings is not recursive: if the substitution of AToText results in a new match for AFromText, that match is not replaced.
设置日期分割符,DateSeparator:='/';