看一下这个过程,DecodeDate,应该会有收获的!DecodeDate procedureDecodeDate breaks TDateTime into Year, Month, and Day values.UnitSysUtilsCategorydate/time routinesprocedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);DescriptionThe DecodeDate procedure breaks the value specified as the Date parameter into Year, Month, and Day values. If the given TDateTime value is less than or equal to zero, the year, month, and day return parameters are all set to zero.

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);var
      Present: TDateTime;
      Year, Month, Day, Hour, Min, Sec, MSec: Word;
     begin
      Present:= Now;
      DecodeDate(Present, Year, Month, Day);
      Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
        + IntToStr(Month) + ' of Year ' + IntToStr(Year);
      DecodeTime(Present, Hour, Min, Sec, MSec);
      Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
        + IntToStr(Hour);
    end;
      

  2.   

    换个思路好不好?
    可以直接把日期字符串分解成年月日啊
    decodedate(date,year,month,day)
      

  3.   

    //从MSDN上拷贝下来的,你可以试一下。
    #include <stdio.h>
    #include <string.h>
    char string[] = "A string\tof ,,tokens\nand some  more tokens";
    char seps[]   = " ,\t\n";
    char *token;void main( void )
    {
       printf( "%s\n\nTokens:\n", string );
       /* Establish string and get the first token: */
       token = strtok( string, seps );
       while( token != NULL )
       {
          /* While there are tokens in "string" */
          printf( " %s\n", token );
          /* Get next token: */
          token = strtok( NULL, seps );
       }
    }
      

  4.   

    我这儿有一个获得年月日的子程序,你可以参考一下,或许你可以有所启发,我就部队程序进行修改了。
    int CHousingView::GetYear(CString str)
    {
    if(str=="") return 0;
    int i;
    TCHAR str1;
    CString str2="";
    i=str.Find("年");
        for(int j=0;j<i;j++)
    {
    str1=str.GetAt(j);
    str2=str2+str1;
    }
    return atoi(str2);}int CHousingView::GetDay(CString str)
    {
    if(str=="") return 0;
    int i,k;
    TCHAR str1;
    CString str2="";
    i=str.Find("月");
    k=str.Find("日");
        for(int j=i+2;j<k;j++)
    {
    str1=str.GetAt(j);
    str2=str2+str1;
    }
    return atoi(str2);}
    int CHousingView::GetMonth(CString str)
    {
    if(str=="") return 0;
    int i,k;
    TCHAR str1;
    CString str2="";
    i=str.Find("年");
    k=str.Find("月");
        for(int j=i+2;j<k;j++)
    {
    str1=str.GetAt(j);
    str2=str2+str1;
    }
    return atoi(str2);}
      

  5.   

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

  6.   


    var
      Present: TDateTime;
      Year, Month, Day, Hour, Min, Sec, MSec: Word;
      sDateTime :string;
    begin
      sDateTime := '01/01/11';
      Present:= StrToDateTime(sDateTime);
      DecodeDate(Present, Year, Month, Day);
      Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
        + IntToStr(Month) + ' of Year ' + IntToStr(Year);
      DecodeTime(Present, Hour, Min, Sec, MSec);
      Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
        + IntToStr(Hour);
    end; 
      

  7.   

    我看用自定义函数好一点,通用,strtodatetime('01/12/10')是会出错的。
    procedure getYMDfromStr(datestr:string;var y,m,d:string);
    var tmpstr:string;
        i,count:integer;
    begin
       for i:=1 to 2 do
       begin
          count:=pos('/',datestr);
          if count<0 then exit;
          tmpstr:=copy(datestr,1,count-1);
          case i of
             1:y:=tmpstr;
             2:m:=tmpstr;
          end;
          delete(datestr,1,count);
       end;
       d:=datestr;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var y,m,d:string;
    begin
       getymdfromstr(edit1.Text,y,m,d);
       showmessage('y:'+y+'m:'+m+'d:'+d);
    end;
      

  8.   

    月份如果固定在等二个/和等3个/之间,用pos&copy可以实现(循环判断),
    用如下方法也可以实现:
    str:='01/2/3'
    var
    test:tstringlist;
    begin
       try
          test:=tstringlist.create;
          test.text:=stringreplace(str,'/',chr(10),[rfReplaceAll]);
          showmessage(test[1]);
       finally
          test.free;
       end;
    end;