SysUtilsStrToTime (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses an edit box and a button on a form. When you enter a time in the edit box in the HH:MM:SS format, the string entered is converted to a TDateTime value. A message saying "Good Morning" or "Good Afternoon" then appears, depending on whether the time entered was in the morning or afternoon.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TDateTime dtTime = StrToTime(Edit1->Text);
  if (dtTime < (TDateTime) 0.50 )
    ShowMessage("Good Morning");
  else
    ShowMessage("Good Afternoon");
}

Uses