DTTransform (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

 This example shows how to use DateUtils routines for transforming a
 TDateTime variable in other date formats.

Code

__fastcall TMainForm::TMainForm(TComponent* Owner)
	: TForm(Owner)
{
  /* Initialize the Date edit-box with the current date and time */
  edDate->Text = DateTimeToStr(Date() + Time());
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btTransformClick(TObject *Sender)
{
  TDateTime DateTime;
  /* Transform the date and change the content of the corresponding
  edit-box according to the selected option */
  if (RadioGroup1->ItemIndex == 0)
	edJulian->Text = FloatToStr
	  (DateTimeToJulianDate(StrToDateTime(edDate->Text)));
  if (RadioGroup1->ItemIndex == 1)
	edModJulian->Text = FloatToStr
	  (DateTimeToModifiedJulianDate(StrToDateTime(edDate->Text)));
  if (RadioGroup1->ItemIndex == 2)
	edUnix->Text = FloatToStr
	  (DateTimeToUnix(StrToDateTime(edDate->Text)));
  if (RadioGroup1->ItemIndex == 3)
	if (TryJulianDateToDateTime(StrToFloat(edJulian->Text),DateTime))
	  edDate->Text = DateTimeToStr
		(JulianDateToDateTime(StrToFloat(edJulian->Text)));
	  else
		ShowMessage("Not a valid Julian date");
  if (RadioGroup1->ItemIndex == 4)
	if (TryModifiedJulianDateToDateTime(StrToFloat(edModJulian->Text),DateTime))
	  edDate->Text = DateTimeToStr
		(ModifiedJulianDateToDateTime(StrToFloat(edModJulian->Text)));
	  else
		ShowMessage("Not a valid modified Julian date");
  if (RadioGroup1->ItemIndex == 5)
	edDate->Text = DateTimeToStr
	  (UnixToDateTime(StrToInt64(edUnix->Text)));
}

Uses

Personal tools
Assistance