RAD Studio VCL Reference
|
Returns a TDateTime value for a specified Hour, Min, Sec, and MSec.
function EncodeTime(Hour: Word; Min: Word; Sec: Word; MSec: Word): TDateTime;
TDateTime EncodeTime(Word Hour, Word Min, Word Sec, Word MSec);
EncodeTime encodes the given hour, minute, second, and millisecond into a TDateTime value.
Valid Hour values are 0 through 23.
Valid Min and Sec values are 0 through 59.
Valid MSec values are 0 through 999.
If the specified values are not within range, EncodeTime raises an EConvertError exception.
The resulting value is a number between 0 and 1 (inclusive) that indicates the fractional part of a day given by the specified time or (if 1.0) midnight on the following day. The value 0 corresponds to midnight, 0.5 corresponds to noon, 0.75 corresponds to 6:00 pm, and so on.
C++ Examples:
/* This example uses three edit controls, a label, and a button on a form. When the button is clicked, the day, month, and year specified in the edit controls is stored in a TDateTime object. Then the TDateTime object is converted to an AnsiString that is displayed in the label. */ void __fastcall TForm1::Button1Click(TObject *Sender) { TDateTime dt; try { dt = EncodeTime((Word)StrToInt(Edit1->Text), (Word)StrToInt(Edit2->Text), (Word)StrToInt(Edit3->Text), (Word)StrToInt(Edit4->Text)); Label1->Caption = TimeToStr(dt); } catch(...) { ShowMessage("Invalid hour, minute, second, or millisecond."); } }
Delphi Examples:
{ This example uses three edit controls, a label, and a button on a form. When the button is clicked, the day, month, and year specified in the edit controls is stored in a TDateTime object. Then the TDateTime object is converted to an AnsiString that is displayed in the label. } procedure TForm1.Button1Click(Sender: TObject); var MyDate: TDateTime; begin MyDate := SysUtils.EncodeTime(StrToInt(Edit1.Text), StrToInt(Edit2.Text), StrToInt(Edit3.Text), StrToInt(Edit4.Text)); Label1.Caption := TimeToStr(MyDate); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|