首先把日期字符串转换成了一个日期型变量,如果StrToDateTime函数报错,则提示;如果没有错,则再用DateTimeToStr函数把日期型变量转换成标准格式,如'1999-12-31',这时候你就可以得到正确的年月日了。
  另外,要定义你所想要的标准格式,预先设置全局变量ShortDateFormat。

解决方案 »

  1.   

    在程序的开头加入如下语句:
    longtimeformat:= 'hh:mm:ss';
    longdateformat:= 'yyyy''年''mm''月''dd''日''';
    shortdateformat := 'yyyy-mm-dd';
    twodigityearcenturywindow := 50;这样就保证了程序中的日期按你的要求显示。如果要分离日期的,可以使用
    var
      year,month,date :word;
    decodedate(now,year,month,date)实现
      

  2.   

    var
      date1:tdatetime;
      year1,month1,day1:word;   
    begin
       date1:=now;                      //取当前时间
       decodedate(date1,year1,month1,day1);
       qrly1.caption:=inttostr(year1);  //年
       qrlm1.caption:=inttostr(month1);  //月
       qrld1.caption:=inttostr(day1);    //日
    end;
      

  3.   

    其实好简单但也要我写这么多呢,有银子没有?
    DateString: string;
    tempString: string;
    i,CharLoc,lenthStr:integer;
    myYear,myMon,MyDay:integer;
    //……
         //给DateString赋值 请保证你的日期是正确的哦,不要是“我0//9”之类的内容lengthStr:= StrLen(PChar(DateString));
    for i:=1 to  lengthStr  do
       begin
         if (DateString[i]='-') or (DateString[i]='\')
           then  begin
              CharLoc:=i;
              break;
           end;
       end;  tempString:=DateString;
      delete(tempString,CharLoc,lengthStr-CharLoc+1);  //  得到年的字符串
      myYear:=StrToInt(tempString);       //年年年年年年年年年年年年  delete(DateString,1,CharLoc);       //去掉年  lengthStr:= StrLen(PChar(DateString));
      for i:=1 to  lengthStr  do
       begin
         if (DateString[i]='-') or (DateString[i]='\')
           then  begin
              CharLoc:=i;
              break;
           end;
       end;  tempString:=DateString;       //与上面代码一样
      delete(tempString,CharLoc,lengthStr-CharLoc+1);  //  得到月的字符串
      myMon:=StrToInt(tempString);       //月月月月月月月月  delete(DateString,1,CharLoc);       //去掉月  myDay:=StrToInt(DateString);    //日日日日日日日日日日日日
      

  4.   

    看看这个函数的用法
    function Pos(Substr: string; S: string): Integer;