![]() |
AW: strftime für Delphi ?
Zitat:
|
AW: strftime für Delphi ?
Es ist auch relativ simpel so einen Parser zu basteln.
Hier ein Anfang
Delphi-Quellcode:
Man braucht jetzt nur nach den Case-Teil um die anderen Zeichen ergänzen und fertig ist es.
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; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:17 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