AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

strftime für Delphi ?

Ein Thema von myicq · begonnen am 11. Jan 2019 · letzter Beitrag vom 12. Jan 2019
 
Schokohase
(Gast)

n/a Beiträge
 
#12

AW: strftime für Delphi ?

  Alt 12. Jan 2019, 12:48
Es ist auch relativ simpel so einen Parser zu basteln.

Hier ein Anfang
Delphi-Quellcode:
function strftime(const Format: string; Value: TDateTime; const FormatSettings: TFormatSettings): string; overload;
var
  controlChar: Boolean;
  current: Char;
begin
  Result := string.Empty;
  controlChar := false;
  for current in Format do
  begin
    if controlChar then
    begin
      case current of
        // ---
        // Tag
        // ---
        'd':
          // Tag des Monats als zweistellige Zahl (ggf. mit vorangestellten Nullen)
          // 01 bis 31
          Result := Result + FormatDateTime('dd', Value, FormatSettings);
        // -----
        // Monat
        // -----
        'm':
          // Zweistellige numerische Darstellung des Monats
          // 01 (für Januar) bis 12 (für Dezember)
          Result := Result + FormatDateTime('mm', Value, FormatSettings);
        // ----
        // Jahr
        // ----
        'Y':
          // Vierstellige numerische Darstellung des Jahres
          // Beispiel: 2038
          Result := Result + FormatDateTime('yyyy', Value, FormatSettings);
        // -------------
        // Verschiedenes
        // -------------
        'n':
          // Ein Zeilenvorschubzeichen ("\n")
          Result := Result + sLineBreak;
        't':
          // Ein Tabulatorzeichen ("\t")
          Result := Result + #9;
        '%':
          // Ein Tabulatorzeichen ("\t")
          Result := Result + '%';
      else
        Result := Result + '%' + current;
      end;
      controlChar := False;
    end
    else
    begin
      if current <> '%then
      begin
        Result := Result + current;
      end
      else
        controlChar := true;
    end;
  end;
  if controlChar then
    Result := Result + '%';
end;

function strftime(const Format: string; Value: TDateTime): string; overload;
begin
  Result := strftime(Format, Value, System.SysUtils.FormatSettings);
end;

function strftime(const Format: string): string; overload;
begin
  Result := strftime(Format, System.SysUtils.Now());
end;
Man braucht jetzt nur nach den Case-Teil um die anderen Zeichen ergänzen und fertig ist es.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:07 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz