unit ConvertToCn;interfaceuses Controls, Sysutils; function Day(const Value: TDateTime): Integer;
function Month(const Value: TDateTime): Integer;
function Year(const Value: TDateTime): Integer; function DatePart(const dpName: String; const Value: TDateTime): Integer;
implementationfunction Day(const Value: TDateTime): Integer;
begin
Result := DatePart('dd', Value);
end;function Month(const Value: TDateTime): Integer;
begin
Result := DatePart('mm', Value);
end;function Year(const Value: TDateTime): Integer;
begin
Result := DatePart('yyyy', Value);
end;function DatePart(const dpName: String; const Value: TDateTime): Integer;
begin
Result := StrToInt(FormatDateTime(dpName, Value));
end;
end.
//这是我写的一个单元,拿去用吧~~
function Month(const Value: TDateTime): Integer;
function Year(const Value: TDateTime): Integer; function DatePart(const dpName: String; const Value: TDateTime): Integer;
implementationfunction Day(const Value: TDateTime): Integer;
begin
Result := DatePart('dd', Value);
end;function Month(const Value: TDateTime): Integer;
begin
Result := DatePart('mm', Value);
end;function Year(const Value: TDateTime): Integer;
begin
Result := DatePart('yyyy', Value);
end;function DatePart(const dpName: String; const Value: TDateTime): Integer;
begin
Result := StrToInt(FormatDateTime(dpName, Value));
end;
end.
//这是我写的一个单元,拿去用吧~~
function Month(const Value: TDateTime): Integer;
function Year(const Value: TDateTime): Integer; function DatePart(const dpName: String; const Value: TDateTime): Integer;
implementationfunction Day(const Value: TDateTime): Integer;
begin
Result := DatePart('dd', Value);
end;function Month(const Value: TDateTime): Integer;
begin
Result := DatePart('mm', Value);
end;function Year(const Value: TDateTime): Integer;
begin
Result := DatePart('yyyy', Value);
end;function DatePart(const dpName: String; const Value: TDateTime): Integer;
begin
Result := StrToInt(FormatDateTime(dpName, Value));
end;
end.
//这是我写的一个单元,拿去用吧~~
DecodeTime
具体用法看帮助
function EncodeDate(Year, Month, Day: Word): TDateTime;procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);//时间的组合与分离
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);//获得当前年、月、日和小时、分、秒、毫秒
procedure TForm1.Button1Click(Sender: TObject);
var
yyyy,mm,dd,h,m,s,ms:word;
begin
decodedate(now,yyyy,mm,dd);
decodetime(now,h,m,s,ms);
edit1.Text:=inttostr(yyyy);
edit2.Text:=inttostr(mm);
edit3.Text:=inttostr(dd);
edit4.Text:=inttostr(h);
edit5.Text:=inttostr(m);
edit6.Text:=inttostr(s);
end;