AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

strftime für Delphi ?

Ein Thema von myicq · begonnen am 11. Jan 2019 · letzter Beitrag vom 12. Jan 2019
Antwort Antwort
Seite 2 von 2     12
Benutzerbild von scrat1979
scrat1979

Registriert seit: 12. Jan 2007
Ort: Sulzbach a.d. Murr
1.028 Beiträge
 
Delphi 10.4 Sydney
 
#11

AW: strftime für Delphi ?

  Alt 12. Jan 2019, 11:41
Wenn du bei
Code:
Aus %%Y wird %Y
alle %Y durch YYYY ersetzt, dann erhälst du
Code:
Aus %YYYY wird YYYY
Du brauchst aber für die korrekte Formatierung
Code:
"Aus %Y wird "YYYY
Ah, alles klar. Klingt irgendwie logisch
Michael Kübler
  Mit Zitat antworten Zitat
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
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 19:25 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz