如何将DateTimePicker的日期拆分开年,月,日,分别显示在三个LABEL上?

解决方案 »

  1.   

    lbYear.text:=Copy(DateTimePicker1.text,1,4);
    lbMonth.text:=Copy(DateTimePicker1.text,7,2);
    lbDay.text:=Copy(DateTimePicker1.text,11,4);
      

  2.   

    用:
    procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
      

  3.   

    lbYear.text:=format('yyyy',datetimepicker1.date);
    lbmonth.text:=format('mm',datetimepicker1.date);
    lbday.text:=format('dd',datetimepicker1.date);
      

  4.   

    楼上的假定了DateTimePicker1的日期格式,这是不对的lbYear.text:=FormatDateTime('yyyy',DateTimePicker1.DateTime);
    lbMonth.text:=FormatDateTime('m',DateTimePicker1.DateTime);
    lbDay.text:=FormatDateTime('d',DateTimePicker1.DateTime);
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Label1.caption:=FormatDateTime('yyyy',DateTimePicker1.date);
    Label2.caption:=FormatDateTime('mm',DateTimePicker1.date);
    Label3.caption:=FormatDateTime('dd',DateTimePicker1.date);
    end;
      

  6.   

    DecodeDate(Now,Year,Month,Day);
     DecodeTime(Now,hour,minu,Sec,MSec);
      

  7.   

    NOW就是你的时间 可以用DATETIMEPICKER.date代替
      

  8.   

    用aiirii(ari-爱的眼睛)的方法就行呀。很简单的,而且Delphi自己的源代码里也是用这个的。
      

  9.   

    var yy,mm,dd:word
    begin
    DecodeDate(DateTimePicker.date,yy,mm,dd);
    label1.caption:=inttostr(yy);
    label2.caption:=inttostr(mm);
    label3.caption:=inttostr(dd);
    end;
      

  10.   

    爱的眼睛说的很好了,我也一直那样用的,很简单的
    当然用FORMATDATETIME也可以的,看你自己了,DELPHI的帮助上都有的
      

  11.   

    var yy,mm,dd:word
    begin
    DecodeDate(DateTimePicker.date,yy,mm,dd);
    label1.caption:=inttostr(yy);
    label2.caption:=inttostr(mm);
    label3.caption:=inttostr(dd);
    end;
      

  12.   

    label1.caption:=inttostr(yearof(DateTimePicker1.date));
    label2.caption:=inttostr(monthof(DateTimePicker1.date));
    label3.caption:=inttostr(dayof(DateTimePicker1.date));
      

  13.   

    最快的方法:
    pst : TSystemTime;SendMessage(DateTimePicker1.Handle, $1001, 0, Longint(@pst));
    Label1.caption := inttoStr(pst.wyear);
    label2.caption := IntToStr(pst.wMonth);
    label3.caption := IntToStr(pst.wday);