AGB  ·  Datenschutz  ·  Impressum  







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

FormatSettings for Dummies

Ein Thema von haentschman · begonnen am 12. Apr 2016 · letzter Beitrag vom 1. Mai 2019
Antwort Antwort
Seite 2 von 4     12 34      
Benutzerbild von baumina
baumina

Registriert seit: 5. Mai 2008
Ort: Oberschwaben
1.275 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 06:14
Wenn ich einen Blick in die SysUtils werfe, sehe ich dass es 'HH' als Formatierung nicht gibt. Es gibt nur 'hh', wenn man keine 24-Stundenanzeige will, wird das über am/pm geregelt.

Zitat:
{ FormatDateTime formats the date-and-time value given by DateTime using the
format given by Format. The following format specifiers are supported:

c Displays the date using the format given by the ShortDateFormat
global variable, followed by the time using the format given by
the LongTimeFormat global variable. The time is not displayed if
the fractional part of the DateTime value is zero.

d Displays the day as a number without a leading zero (1-31).

dd Displays the day as a number with a leading zero (01-31).

ddd Displays the day as an abbreviation (Sun-Sat) using the strings
given by the ShortDayNames global variable.

dddd Displays the day as a full name (Sunday-Saturday) using the strings
given by the LongDayNames global variable.

ddddd Displays the date using the format given by the ShortDateFormat
global variable.

dddddd Displays the date using the format given by the LongDateFormat
global variable.

g Displays the period/era as an abbreviation (Japanese and
Taiwanese locales only).

gg Displays the period/era as a full name.

e Displays the year in the current period/era as a number without
a leading zero (Japanese, Korean and Taiwanese locales only).

ee Displays the year in the current period/era as a number with
a leading zero (Japanese, Korean and Taiwanese locales only).

m Displays the month as a number without a leading zero (1-12). If
the m specifier immediately follows an h or hh specifier, the
minute rather than the month is displayed.

mm Displays the month as a number with a leading zero (01-12). If
the mm specifier immediately follows an h or hh specifier, the
minute rather than the month is displayed.

mmm Displays the month as an abbreviation (Jan-Dec) using the strings
given by the ShortMonthNames global variable.

mmmm Displays the month as a full name (January-December) using the
strings given by the LongMonthNames global variable.

yy Displays the year as a two-digit number (00-99).

yyyy Displays the year as a four-digit number (0000-9999).

h Displays the hour without a leading zero (0-23).

hh Displays the hour with a leading zero (00-23).

n Displays the minute without a leading zero (0-59).

nn Displays the minute with a leading zero (00-59).

s Displays the second without a leading zero (0-59).

ss Displays the second with a leading zero (00-59).

z Displays the millisecond without a leading zero (0-999).

zzz Displays the millisecond with a leading zero (000-999).

t Displays the time using the format given by the ShortTimeFormat
global variable.

tt Displays the time using the format given by the LongTimeFormat
global variable.

am/pm Uses the 12-hour clock for the preceding h or hh specifier, and
displays 'am' for any hour before noon, and 'pm' for any hour
after noon. The am/pm specifier can use lower, upper, or mixed
case, and the result is displayed accordingly.

a/p Uses the 12-hour clock for the preceding h or hh specifier, and
displays 'a' for any hour before noon, and 'p' for any hour after
noon. The a/p specifier can use lower, upper, or mixed case, and
the result is displayed accordingly.

ampm Uses the 12-hour clock for the preceding h or hh specifier, and
displays the contents of the TimeAMString global variable for any
hour before noon, and the contents of the TimePMString global
variable for any hour after noon.

/ Displays the date separator character given by the DateSeparator
global variable.

: Displays the time separator character given by the TimeSeparator
global variable.

'xx' Characters enclosed in single or double quotes are displayed as-is,
"xx" and do not affect formatting.

Format specifiers may be written in upper case as well as in lower case
letters--both produce the same result.

If the string given by the Format parameter is empty, the date and time
value is formatted as if a 'c' format specifier had been given.

The following example:

S := FormatDateTime('"The meeting is on" dddd, mmmm d, yyyy, ' +
'"at" hh:mm AM/PM', StrToDateTime('2/15/95 10:30am'));

assigns 'The meeting is on Wednesday, February 15, 1995 at 10:30 AM' to
the string variable S. }
Hinter dir gehts abwärts und vor dir steil bergauf ! (Wolfgang Ambros)
  Mit Zitat antworten Zitat
Benutzerbild von haentschman
haentschman

Registriert seit: 24. Okt 2006
Ort: Seifhennersdorf / Sachsen
5.297 Beiträge
 
Delphi 12 Athens
 
#12

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 06:21
Moin und danke....

Das weiß ich alles. Ich will aber wissen wie das Zeitformat, was der Nutzer eingestellt hat, aussieht und anwenden. Primär geht es nur um die in FormatSettings gelieferten Werte. Die sind definitiv beim Zeitformat falsch. Du kannst einstellen was du willst. Der Formatstring für die Zeit ist immer gleich.
Ich habe mir schon eine Funktion gebaut die die "Unzulänglichkeiten" ausbügelt. Das kann es doch aber nicht sein.

Geändert von haentschman (13. Apr 2016 um 06:25 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#13

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 08:17
Dann lies dich in die entsprechenden API-Funktionen ein und bau dir das so wie du das haben willst.

Kleiner Tipp: Da hat sich über die Zeit von Windows XP über Vista und 7 ... etwas (einiges) getan, was du auch alles berücksichtigen musst. Mal sehen auf welchen Ansatz du kommst.

Mit Delphi-Referenz durchsuchenSystem.SysUtils.GetLocaleStr kannst du sozusagen direkt auslesen, was das OS zurückgibt.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Benutzerbild von haentschman
haentschman

Registriert seit: 24. Okt 2006
Ort: Seifhennersdorf / Sachsen
5.297 Beiträge
 
Delphi 12 Athens
 
#14

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 10:45
Danke...
Zitat:
Da hat sich über die Zeit von Windows XP über Vista und 7
...da muß ich mal sagen das interessiert mich nicht. Ich lese die FormatSettings (dafür sind sie da) und erwarte korrekte Werte.
Stelle mal bitte in deinen Regionseinstellungen das kurze Zeitformat auf HH:mm Uhr (Vorlage). Dann zeige mir wie du mit Hilfe der Formatsettings das 13:48 Uhr (so wollte es ja der Nutzer) ohne zusätzliche Korrekturen in ein Label schreibst.

Ich will doch nur bestätigt haben, das auch bei Euch die Zeitformatierung in den FormatSettings falsch ist.
  Mit Zitat antworten Zitat
Der schöne Günther

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

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 10:58
Klar, das wird bei jedem so sein.
Miniaturansicht angehängter Grafiken
shorttimesettings.png  
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#16

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 11:21
Die FormatSettings sind dafür da, dass Delphi mit diesen arbeiten kann und zwar auf jeder Plattform. Somit sind diese Einstellungen dort entsprechend gleichgeschaltet.

Um damit zu arbeiten verwendet man ganz simpel die Funktionen, die optional die FormatSettings als Argument anbieten. Alles, was nach Datum/Zeit riecht wird intern von System.SysUtils.DateTimeToString() (nur intern verfügbar) in einen String umgewandelt.

Wenn du wissen willst, was jetzt explizit bei dem OS an EInstellungen original drin stehen, dann musst du das über den Weg auslesen, den das OS zur Verfügung stellt.

Eigentlich nicht so schwer zu verstehen ...
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#17

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 11:33
Nur mal so gesagt:
1. Warum kommt hier Label.Caption := FormatDateTime(Now, FormatSettings.ShortDateFormat) 12/04/2016 statt 12.04.2016 ?
Das kann ich noch nicht einmal kompilieren

Das hier schon
Label1.Caption := FormatDateTime( FormatSettings.ShortDateFormat, Now ); Hier mal ein kleines Beispielprogramm, wo man auch live die Änderungen sehen kann
Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.AppEvnts;

type
  TForm1 = class( TForm )
    Label1: TLabel;
    ApplicationEvents1: TApplicationEvents; { OnSettingChange = ApplicationEvents1SettingChange }
    procedure ApplicationEvents1SettingChange(Sender: TObject; Flag: Integer;
      const Section: string; var Result: Integer);
    procedure FormShow(Sender: TObject);
  private
    procedure PresentData;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ApplicationEvents1SettingChange(Sender: TObject; Flag: Integer;
  const Section: string; var Result: Integer);
begin
  PresentData;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  PresentData;
end;

procedure TForm1.PresentData;
begin
  Label1.Caption := FormatDateTime( FormatSettings.ShortDateFormat, Now );
end;

end.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Benutzerbild von haentschman
haentschman

Registriert seit: 24. Okt 2006
Ort: Seifhennersdorf / Sachsen
5.297 Beiträge
 
Delphi 12 Athens
 
#18

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 11:37
Zitat:
Um damit zu arbeiten verwendet man ganz simpel die Funktionen, die optional die FormatSettings als Argument anbieten. Alles, was nach Datum/Zeit riecht wird intern von System.SysUtils.DateTimeToString() (nur intern verfügbar) in einen String umgewandelt.
...aber mit falschem Zeitformat.
Zitat:
Das kann ich noch nicht einmal kompilieren
...sorry war auf dem Handy aus dem Hut getippt. Value und FormatString ist umgekehrt.
Delphi-Quellcode:
procedure TForm1.PresentData;
begin
  Label1.Caption := FormatDateTime( FormatSettings.ShortDateFormat, Now );
end;
...jetzt nimmst du mal ShortTimeFormat und versuchst in der Region Englisch mit 12 Std. Anzeige und AM/PM einzustellen. Alternativ kannst du auch unser 24 Stundenformat probieren... es kommt immer 12 Std.Format ohne AM/PM raus.


Wir brechen hier ab. Ich habe mir das selbst für unsere Zwecke korrigiert.

Danke an alle...

Geändert von haentschman (13. Apr 2016 um 11:44 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#19

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 11:43
Beim Zeitformat hat Emba allerdings geschlafen, das wird nicht so übernommen, wie in den Windows-Einstellungen eingetragen.

Delphi-Quellcode:
  TimePrefix := '';
  TimePostfix := '';
  if StrToIntDef(GetLocaleStr(Locale, LOCALE_ITLZERO, '0'), 0) = 0 then
    HourFormat := 'h'
  else
    HourFormat := 'hh';
  if StrToIntDef(GetLocaleStr(Locale, LOCALE_ITIME, '0'), 0) = 0 then
    if StrToIntDef(GetLocaleStr(Locale, LOCALE_ITIMEMARKPOSN, '0'), 0) = 0 then
      TimePostfix := ' AMPM'
    else
      TimePrefix := 'AMPM ';
  Result.ShortTimeFormat := TimePrefix + HourFormat + ':mm' + TimePostfix; // <- DA
  Result.LongTimeFormat := TimePrefix + HourFormat + ':mm:ss' + TimePostfix; // <- DA
Da bleibt nur der Weg über das OS (auslesen, ummodeln, verwenden)
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo (13. Apr 2016 um 11:46 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von haentschman
haentschman

Registriert seit: 24. Okt 2006
Ort: Seifhennersdorf / Sachsen
5.297 Beiträge
 
Delphi 12 Athens
 
#20

AW: FormatSettings for Dummies

  Alt 13. Apr 2016, 11:44
Davon rede ich die ganze Zeit... na endlich.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 4     12 34      


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 23:18 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