Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#4

AW: Datumsformat (TT.MM.JJJJ) anzeigen

  Alt 6. Jun 2018, 11:22
Knifflige Frage.

Die paar Leute die sich im Internet die gleiche Frage gestellt haben ([1], [2]) hast du sicher auch schon gefunden. Da das Format mit 'yyyy' oder 'dd' dokumentiert und sprachunabhängig ist [3] musst du die halt durch deine eigene lokalisierte Fassung ersetzen. Beispielsweise so in der Art:
Delphi-Quellcode:
uses
   System.SysUtils,
   WinApi.Windows,
   Vcl.Dialogs;

function getShortDateFormat(): String;
const
   lcType = LOCALE_SSHORTDATE;
var
   str: String;
   bufferSize: Integer;
begin
   bufferSize := GetLocaleInfoEx(
      PChar(LOCALE_NAME_USER_DEFAULT),
      lcType,
      nil,
      0
   );
   str := String.Create(#0, bufferSize);
   Win32Check(
      GetLocaleInfoEx(
         PChar(LOCALE_NAME_USER_DEFAULT),
         lcType,
         PChar(str),
         bufferSize
      ) = bufferSize
   );
   Result := Str;
end;

procedure p();
resourcestring
   shortDay = 'T';
   shortMonth = 'M';
   shortYear = 'Y';
var
   shortDateFormat: String;
begin
   shortDateFormat :=
      getShortDateFormat()
      .Replace('d', shortDay)
      .Replace('M', shortMonth)
      .Replace('y', shortYear);
   ShowMessage(shortDateFormat);
end;

[1] http://forums.codeguru.com/showthrea...indowsversions
[2] https://stackoverflow.com/q/12591993/2298252
[3] https://technet.microsoft.com/de-de/.../dd317787.aspx

Geändert von Der schöne Günther ( 6. Jun 2018 um 11:25 Uhr)
  Mit Zitat antworten Zitat