请问怎样让TryStrToDatetime('1999年1月1日',D)返回True?

解决方案 »

  1.   

    AnsiReplaceStr函数在strUtils单元中var
        str: string;
        D: TDateTime;
    begin
        str := AnsiReplaceStr('2003年5月11日','年','-');
        str := AnsiReplaceStr(str,'月','-');
        str := AnsiReplaceStr(str,'日','');
        if TryStrToDatetime(str,D) then
            ShowMessage(str);
    end
      

  2.   

    楼上误解我的意思了,
    其实我想做一个合法日期验证过程
    function CheckDatetime(const s:string):boolean;
    当s='1991年1月1日'或'1991/1/1','1月1日'等时返回真记得VB中IsDate函数有此功能。
      

  3.   

    还是做个DateForm让用户选好点,不要让用户输入,方便又不会出错
    begin
    Edit.Text.enable:=False;
    application.CreateForm(TDateForm,DateForm);
     if (DateForm.ShowModal=mrok) then
      begin
       Edit2.Text:='';
       Edit2.Text:=DateTimeToStr(DateForm.date1.Date);
      end;
      DateForm.Free; 
    end;
      

  4.   

    TryStrToDatetime不可能实现的,里面的ScanDate有问题。自己从新写吧,并不复杂。以前曾经写过,数据迁移经常要用这样的函数。
      

  5.   

    问题是:客户总认为'1991年1月1日'或'1991/1/1','1月1日'都是合法的日期,而不管系统时间设置情况。说白了,就是把以前各式各样字符串('1991年1月1日'或'1991/1/1','1月1日')转换成DELPHI的TDatetime类型,功能类似于VB中的IsDate,CDate函数.
      

  6.   

    to:lijinghe1(副乡长)
      OK,我试试!