DateTimeRecode (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example replaces specific parts of a TDateTime variable with values given by the user.

-> TDateTime DateTime;

Code

__fastcall TMainForm::TMainForm(TComponent* Owner)
	: TForm(Owner)
{
  /* Get the current date and time. */
  DateTime = Date() + Time();
  /* Write the day of the week, date, and time. */
  if (NthDayOfWeek(DateTime) == DayMonday)
	edDate->Text = "Monday, " + DateTimeToStr(DateTime);
  if (NthDayOfWeek(DateTime) == DayTuesday)
	edDate->Text = "Tuesday, " + DateTimeToStr(DateTime);
  if (NthDayOfWeek(DateTime) == DayWednesday)
	edDate->Text = "Wednesday, " + DateTimeToStr(DateTime);
  if (NthDayOfWeek(DateTime) == DayTuesday)
	edDate->Text = "Tuesday, " + DateTimeToStr(DateTime);
  if (NthDayOfWeek(DateTime) == DayFriday)
	edDate->Text = "Friday, " + DateTimeToStr(DateTime);
  if (NthDayOfWeek(DateTime) == DaySaturday)
	edDate->Text = "Saturday, " + DateTimeToStr(DateTime);
  if (NthDayOfWeek(DateTime) == DaySunday)
	edDate->Text = "Sunday, " + DateTimeToStr(DateTime);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btRecodeClick(TObject *Sender)
{
  /* Modify the TDateTime variable, according to the user's options. */
  if (cbRecodeDay->Checked && cbRecodeMonth->Checked && cbRecodeYear->Checked &&
	cbRecodeHour->Checked && cbRecodeMinute->Checked &&
	cbRecodeSecond->Checked && cbRecodeMilliSecond->Checked)
  DateTime = RecodeDateTime(DateTime,
	StrToInt(edYear->Text),StrToInt(edMonth->Text),StrToInt(edDay->Text),
	StrToInt(edHour->Text),StrToInt(edMinute->Text),StrToInt(edSecond->Text),
	StrToInt(edMilliSecond->Text));
  else
  if (cbRecodeDay->Checked && cbRecodeMonth->Checked && cbRecodeYear->Checked)
  DateTime = RecodeDate(DateTime,
	StrToInt(edYear->Text),StrToInt(edMonth->Text),StrToInt(edDay->Text));
  else
  if (cbRecodeHour->Checked && cbRecodeMinute->Checked &&
	cbRecodeSecond->Checked && cbRecodeMilliSecond->Checked)
  DateTime = RecodeTime(DateTime,StrToInt(edHour->Text),
	StrToInt(edMinute->Text),StrToInt(edSecond->Text),StrToInt(edMilliSecond->Text));
  else
  {
  if (cbRecodeDay->Checked)
	DateTime = RecodeDay(DateTime,StrToInt(edDay->Text));
  if (cbRecodeMonth->Checked)
	DateTime = RecodeMonth(DateTime,StrToInt(edMonth->Text));
  if (cbRecodeYear->Checked)
	DateTime = RecodeYear(DateTime,StrToInt(edYear->Text));
  if (cbRecodeHour->Checked)
	DateTime = RecodeHour(DateTime,StrToInt(edHour->Text));
  if (cbRecodeMinute->Checked)
	DateTime = RecodeMinute(DateTime,StrToInt(edMinute->Text));
  if (cbRecodeSecond->Checked)
	DateTime = RecodeSecond(DateTime,StrToInt(edSecond->Text));
  if (cbRecodeMilliSecond->Checked)
	DateTime = RecodeMilliSecond(DateTime,StrToInt(edMilliSecond->Text));
  }
  edDate->Text = DateTimeToStr(DateTime);
}

Uses