![]() |
strftime für Delphi ?
Hallo alle schlaue,
gibt es irgendwo eine strftime() Library für Delphi ? Also, eine Funktion ähnlich in php, wo ich gleiches Formattierungsbild eingeben kann, ergebniss String.
Code:
habe soweit nichts gefunden
mystring := strftime('Heute ist %Y %m %d');
|
AW: strftime für Delphi ?
![]()
Delphi-Quellcode:
str := System.SysUtils.FormatDateTime('"Heute ist "yyyy mm dd',System.SysUtils.Now());
|
AW: strftime für Delphi ?
Danke für das Antwort. Klar kenne ich die Formatcodes von Delphi.
In dieser Fall brauche ich aber die formatcodes von strftime() zu behandeln. Ich kann das wenn notwendig selbst umsetzen. Aber hätte jemand das schon gemacht.. |
AW: strftime für Delphi ?
Liste der Anhänge anzeigen (Anzahl: 2)
Ich habe beim neusuche herausgefunden das es strftime() gibt in MSVCRT.DLL. Das würde mir reichen.
Aber : ich mache irgendwas falsch ? Gefunden habe ich das hier: ![]() Mein Code + Unit im Anhang. Ich bekomme kein Fehler beim call an _strftime(), aber auch kein ergebniss. Was mache ich falsch ? |
AW: strftime für Delphi ?
Zitat:
|
AW: strftime für Delphi ?
Zitat:
|
AW: strftime für Delphi ?
Zitat:
|
AW: strftime für Delphi ?
Zitat:
Code:
rauskommen müsste durch
Aus %%Y wird %Y
Delphi-Quellcode:
strftime
Code:
Der passende Format-String für Delphi wäre
Aus %Y wird 2019
Code:
Meine Einschätzung: Es ist einfacher den Formatstring so wie er ist zu parsen und direkt die Werte zu ersetzen als diesen erst umzuformen (da muss man auch parsen) und dann durch
"Aus %Y wird "yyyy
Delphi-Quellcode:
zu jagen.
FormatDateTime
|
AW: strftime für Delphi ?
Zitat:
EDIT: Klar, direkt parsen ist natürlich besser :) |
AW: strftime für Delphi ?
Wenn du bei
Code:
alle
Aus %%Y wird %Y
Delphi-Quellcode:
durch
%Y
Delphi-Quellcode:
ersetzt, dann erhälst du
YYYY
Code:
Du brauchst aber für die korrekte Formatierung
Aus %YYYY wird YYYY
Code:
"Aus %Y wird "YYYY
|
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 13:21 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