给定年月日,要求把它转化为是一年中的第几天!
谢谢!

解决方案 »

  1.   

    use DateUtils这个单元
    Label1.Caption:=inttostr(dayoftheyear(Date));
      

  2.   

    //如果是功能就按如上代码//如果是算法参考如下代码function IsLeapYear(Year: Word): Boolean; //返回是否是闰年
    begin
      Result := (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0));
    end;function DayOfTheYear(Year: Word; Month: Word; Day: Word): Word;
    var
      I: Integer;
    begin
      Result := Day;
      for I := 1 to Month - 1 do
      begin
        case I of
          1, 3, 5, 7, 8, 10, 12: Inc(Result, 31); //大月31天
          4, 6, 9, 11: Inc(Result, 30); //小月30天
          2: Inc(Result, 28 + Ord(IsLeapYear(Year))); //平年28天,闰年多1天
        end;
      end;
    end;