DelphiBasics
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
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.


 
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

  ShowMessage('Date set to '+DateToStr(myDate));
  ShowMessage('Time set to '+TimeToStr(myDate));
end;
Show full unit code
   Date set to 30/12/1899
   Time set to 12:34:56.789
 
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page