本文整理自网络,侵删。
RecodeDateTime、RecodeDate、RecodeTime、RecodeYear ... 修改时间
DateUtils.RecodeDateTime();
DateUtils.RecodeDate();
DateUtils.RecodeTime();
DateUtils.RecodeYear();
DateUtils.RecodeMonth();
DateUtils.RecodeDay();
DateUtils.RecodeHour();
DateUtils.RecodeMinute();
DateUtils.RecodeSecond();
DateUtils.RecodeMilliSecond();
DateUtils.TryRecodeDateTime();
--------------------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses DateUtils;
procedure TForm1.FormCreate(Sender: TObject);
const
st = 'yyyy-m-d h:n:s:z';
var
t1, t2: TDateTime;
begin
t1 := EncodeDateTime(2001, 1, 1, 1, 1, 1, 1);
t2 := RecodeDateTime(t1, 2009, 5, 21, 11, 22, 33, 999);
ShowMessage(FormatDateTime(st, t2)); //2009-5-21 11:22:33:999
t2 := RecodeDate(t1, 2009, 5, 21);
ShowMessage(FormatDateTime(st, t2)); //2009-5-21 1:1:1:1
t2 := RecodeTime(t1, 11, 22, 33, 999);
ShowMessage(FormatDateTime(st, t2)); //2009-1-1 11:22:33:999
t2 := RecodeYear(t1, 2009);
ShowMessage(FormatDateTime(st, t2)); //2009-1-1 1:1:1:1
t2 := RecodeMonth(t1, 5);
ShowMessage(FormatDateTime(st, t2)); //2001-5-1 1:1:1:1
t2 := RecodeDay(t1, 21);
ShowMessage(FormatDateTime(st, t2)); //2001-1-21 1:1:1:1
t2 := RecodeHour(t1, 11);
ShowMessage(FormatDateTime(st, t2)); //2001-1-1 11:1:1:1
t2 := RecodeMinute(t1, 22);
ShowMessage(FormatDateTime(st, t2)); //2001-1-1 1:22:1:1
t2 := RecodeSecond(t1, 33);
ShowMessage(FormatDateTime(st, t2)); //2001-1-1 1:1:33:1
t2 := RecodeMilliSecond(t1, 999);
ShowMessage(FormatDateTime(st, t2)); //2001-1-1 1:1:1:999
if TryRecodeDateTime(t1, 2009, 5, 21, 11, 22, 33, 999, t2) then
ShowMessage(FormatDateTime(st, t2)); //2009-5-21 11:22:33:999
end;
end.
相关阅读 >>
Delphi xe android-uri-管理联系人uri
Delphi 2009 之 tstringbuilder 类[5]: chars[] 属性与 copyto 方法
Delphi自动以管理员身份在vista 和 windows7 下运行程序
Delphi stringgrid 实例5 本例功能:字体修改为居中,红色,20号
更多相关阅读请进入《Delphi》频道 >>