SmartPascal
EncodeTime
Function
Build a TDateTime value from hour, min, sec and msec values SysUtils unit
 function EncodeTime ( const Hour, Min, Sec, MSec : Word ) : TDateTime;
Description
The EncodeTime function generates a TDateTime return value from the passed Hour, Min, Sec and MSec (millisecond) values.
 
The permitted parameter values are :
 
Hour  = 0..23
Min  = 0..59
Sec  = 0..59
MSec  = 0..999

 
If you exceed these values, an EConvertError is raised.
Notes
The Date value for the TDateTime is always set to 30 Dec 1899. Quite why is not clear - it is 2 days before the start of the 20th century.
Related commands
DecodeDate Extracts the year, month, day values from a TDateTime var.
DecodeDateTime Breaks a TDateTime variable into its date/time parts
DecodeTime Break a TDateTime value into individual time values
EncodeDate Build a TDateTime value from year, month and day values
EncodeDateTime Build a TDateTime value from day and time values
 
Example code : Assign a time to a TDateTime variable
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  SysUtils,   // Unit containing the EncodeTime command
  DateUtils,
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  myDate : TDateTime;

begin
  // Set my date variable using the EncodeTime function
  myDate := EncodeTime(12, 34, 56, 789);

  LongTimeFormat := 'hh:mm:ss.z';  // Ensure that MSecs are shown

  ShowMessage('Date set to '+DateToStr(myDate));
  ShowMessage('Time set to '+TimeToStr(myDate));
end;
 
end.
Hide full unit code
   Date set to 30/12/1899
   Time set to 12:34:56.789