ObjectPascal
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
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

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