Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   formato de fecha larga en XE7 (https://www.clubdelphi.com/foros/showthread.php?t=93902)

oscarac 01-05-2019 18:53:40

formato de fecha larga en XE7
 
ya no es posible usar LongDateFormat en XE7 ?

como establezco predeterminadamente la fecha como dd/mm/yyyy
o como puedo hacer un DecodeDate en formato ansi "yyyymmdd"

y que me capture dia, mes y anio ??

Casimiro Notevi 01-05-2019 20:12:11

No creo que lo hayan cambiado. Me extraña mucho.
http://www.delphibasics.co.uk/RTL.asp?Name=DecodeDate
Código Delphi [-]
unit Unit1;
 
interface
 
uses
  SysUtils,   // Unit containing the DecodeDate command
  DateUtils,
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  Form1: TForm1;
 
implementation
{$R *.dfm}  // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);
 var
  myDate : TDateTime;
  myYear, myMonth, myDay : Word;
 begin
  // Set up the myDate variable to have a December 2000 value
  myDate := StrToDate('29/12/2000');

  // Now add a month to this value
  myDate := IncMonth(myDate);

  // And let us see what we get
  DecodeDate(myDate, myYear, myMonth, myDay);
  ShowMessage('myDate now = '+DateToStr(myDate));
  ShowMessage('myDay      = '+IntToStr(myDay));
  ShowMessage('myMonth    = '+IntToStr(myMonth));
  ShowMessage('myYear     = '+IntToStr(myYear));
 end;
 
end.

Casimiro Notevi 01-05-2019 20:13:53

Código Delphi [-]
var
  myDate : TDateTime;
  formattedDate : string;

begin
  myDate := StrToDate('29/02/2000');

  // Display using the default LongDateFormat
  DateTimeToString(formattedDate, 'dddddd', myDate);
  ShowMessage('29/02/2000 using  default = '+formattedDate);

  // Change the display formatting
  LongDateFormat := 'dddd dd of mmmm yyyy';
  DateTimeToString(formattedDate, 'dddddd', myDate);
  ShowMessage('29/02/2000 using override = '+formattedDate);
end;

cloayza 02-05-2019 19:12:21

Estimado OscaraC, aun se puede utilizar el LongFormatDate u otras...

Me tomé la libertad de agregar unas líneas al código que propuso el colega Casimiro Notevi
Existe la variable global FormatSettings, que está en la unit System.SysUtils, acá puede personalizar todo lo referente a formatos a utilizar en su aplicación.

Código Delphi [-]
...
  OldFormat:string;
 begin
      myDate := StrToDate('20/12/2000');

      {1: Formato por defecto...}
      OldFormat:=FormatSettings.ShortDateFormat;
      {2: Cambio de formato...}
      FormatSettings.ShortDateFormat:='yyyy.mm.dd';

      // Now add a month to this value
      myDate := IncMonth(myDate);

      // And let us see what we get
      DecodeDate(myDate, myYear, myMonth, myDay);
      ShowMessage('myDate now = '+DateToStr(myDate));
      ShowMessage('myDay      = '+IntToStr(myDay));
      ShowMessage('myMonth    = '+IntToStr(myMonth));
      ShowMessage('myYear     = '+IntToStr(myYear));

      {3: Restaura formato por defecto...}
      FormatSettings.ShortDateFormat:=OldFormat;

end;

Saludos cordiales


La franja horaria es GMT +2. Ahora son las 01:36:27.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi