DTTransform (Delphi)
Description
This example shows how to use DateUtils routines for transforming a TDateTime variable in other date formats.
Code
procedure TMainForm.btTransformClick(Sender: TObject);
var
DateTime: TDateTime;
begin
{ Transform the date and change the content of the corresponding
edit box according to the selected option. }
if RadioGroup1.ItemIndex = 0 then
edJulian.Text := FloatToStr
(DateTimeToJulianDate(StrToDateTime(edDate.Text)));
if RadioGroup1.ItemIndex = 1 then
edModJulian.Text := FloatToStr
(DateTimeToModifiedJulianDate(StrToDateTime(edDate.Text)));
if RadioGroup1.ItemIndex = 2 then
edUnix.Text := FloatToStr
(DateTimeToUnix(StrToDateTime(edDate.Text)));
if RadioGroup1.ItemIndex = 3 then
if TryJulianDateToDateTime(StrToFloat(edJulian.Text),DateTime) then
edDate.Text := DateTimeToStr
(JulianDateToDateTime(StrToFloat(edJulian.Text)))
else
ShowMessage('Not a valid Julian date');
if RadioGroup1.ItemIndex = 4 then
if TryModifiedJulianDateToDateTime(StrToFloat(edModJulian.Text),DateTime)
then
edDate.Text := DateTimeToStr
(ModifiedJulianDateToDateTime(StrToFloat(edModJulian.Text)))
else
ShowMessage('Not a valid modified Julian date');
if RadioGroup1.ItemIndex = 5 then
edDate.Text := DateTimeToStr
(UnixToDateTime(StrToInt64(edUnix.Text)));
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
{ Initialize the Date edit box with the current date and time. }
edDate.Text := DateTimeToStr(Date + Time);
end;
Uses
- System.DateUtils.DateTimeToJulianDate ( fr | de | ja )
- System.DateUtils.DateTimeToModifiedJulianDate ( fr | de | ja )
- System.DateUtils.DateTimeToUnix ( fr | de | ja )
- System.DateUtils.JulianDateToDateTime ( fr | de | ja )
- System.DateUtils.ModifiedJulianDateToDateTime ( fr | de | ja )
- System.DateUtils.TryJulianDateToDateTime ( fr | de | ja )
- System.DateUtils.TryModifiedJulianDateToDateTime ( fr | de | ja )
- System.DateUtils.UnixToDateTime ( fr | de | ja )