label.caption:=formatdatetiem('yyyymmdd',now());

解决方案 »

  1.   

    up
    用formatdatetime('yyyy',now());     //取年份
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      year,month,day:word;
      date:tdate;
    begin
    date:=now;
    decodedate(date,year,month,day);
    showmessage('year:'+inttostr(year));
    showmessage('month:'+inttostr(month));
    showmessage('day:'+inttostr(day));
    end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      year,month,day:word;
      date:tdate;
    begin
    date:=now;
    decodedate(date,year,month,day);
    showmessage('year:'+inttostr(year));
    showmessage('month:'+inttostr(month));
    showmessage('day:'+inttostr(day));
    end;
    end;
      

  4.   

    还可以用GetLocalTime或getSystemtime 
      其中Tsystem是一个记录:
      PSystemTime = ^TSystemTime;
      TSystemTime = record    wYear: Word;
        wMonth: Word;
        wDayOfWeek: Word;
        wDay: Word;
        wHour: Word;
        wMinute: Word;
        wSecond: Word;
        wMilliseconds: Word;
    不过挺烦的;
      

  5.   

    用WINDOWS API函数:getlocaltime()
    procedure TForm1.Button1Click(Sender: TObject);
    var currenttime:SYSTEMTIME;
    begin
        getlocaltime(currenttime);
        label1.caption:=strtoint(currenttime.wYear);//获得当前年份,并显示在label1上
        //...;
    end;至于其他的数据成员如wMonth等参看楼上所说的。
      

  6.   

    year:=yearof(now);
    month:=monthof(now);
    day:=dayof(now);
      

  7.   

    year:=yearof(now);
    month:=monthof(now);
    day:=dayof(now); 
    or 用WINDOWS API函数:getlocaltime()//嘿嘿