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.



DateUtils-Function

你可能感兴趣的:(DateTime)