呵呵,不好意思写滴C++代码。 不过要提一下的是上面朋友们写的代码:比如StrToDate('2004-1-1')需要当前操作系统的短日期格式为year-month-day或year-day-month(month=day=1),如果当前系统的分隔符为'/'时就会不认识。 ========================== var dt:TDateTime; begin dt:=EncodeDate(2004,1,1); dt:=dt+(135-1); ShowMessage(DateToStr(dt)); end;
result := IncDay (StrToDate ('2004-1-1'),135);
============
lpYear:年份,字符串类型,如'2005'
lpIndex:第几天,如156function GetDateAt(lpYear: String; lpIndex: Integer): TDate;
var
lcDate: TDate;
begin
lcDate:= StrToDate(lpYear + '-1-1') + lpIndex -1;
Result:= lcDate;
end;调用示例:
GetDateAt('2005', 155)
返回的是2005年第155天的日期,TDate类型。
dt=EncodeDate(2004,1,1);//2004年第一天
dt+=(135-1); //第135天
ShowMessage(dt);
不过要提一下的是上面朋友们写的代码:比如StrToDate('2004-1-1')需要当前操作系统的短日期格式为year-month-day或year-day-month(month=day=1),如果当前系统的分隔符为'/'时就会不认识。
==========================
var
dt:TDateTime;
begin
dt:=EncodeDate(2004,1,1);
dt:=dt+(135-1);
ShowMessage(DateToStr(dt));
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uses DateUtils;showmessage(datetimetostr(incday(strtodate('2004-1-1'),135)));//加135天,第136天
showmessage(datetimetostr(incday(strtodate('2004-1-1'),134)));//加134天,第135天///
VAR
sd,td:TDateTime;
y,m,d:word;
begin
y:=2000;
m:=11;
d:=2;
sd:=encodedate(y,m,d);
td:=IncDay(sd,100);
Label1.Caption:=DateTimeTostr(td);
end;
function GetDate(year,days):TDateTime;
begin
result:=encodedate(year,1,1)+days-1;
end;