was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

36 Visitors Online


 
...ein benutzerdefiniertes Format im TDateTimePicker verwenden?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (20):  
     




uses
  
ComCtrls;

const
  
DTM_SETFORMAT = $1005;

procedure TForm1.Button1Click(Sender: TObject);
var
  
sFormat: string;
begin
  
DateTimePicker1.kind := dtkTime;

  // Don't show the seconds, Sekunden nicht anzeigen
  
SendMessage(DateTimePicker1.Handle, DTM_SETFORMAT, 0, Longint(PChar('hh:mm')));

  // To show AM/PM
  
SendMessage(DateTimePicker1.Handle, DTM_SETFORMAT, 0, Longint(PChar('hh:mm tt')));

  // 24-hour clock: Be sure to set Kind to dtkTime
  
DateTime_SetFormat(DateTimePickerTest.Handle, pChar('H:mm:ss'));
  
  // To show Date and Time, Datum und Zeit anzeigen
  // Note that you can only edit the date or the time depending
  // on the Kind (dtkTime or dtkDate).
  
SendMessage(DateTimePicker1.Handle, DTM_SETFORMAT, 0, Longint(PChar('dd/MM/yyyy hh:ss')));

  // You could also use the DateTime_SetFormat macro:
  
DateTime_SetFormat(DateTimePicker1.Handle, PChar('M/d/yyy'));
  
  // Instead of using the DateTime_SetFormat function, you can
  // send a message to the control directly:
  
sFormat := 'dd-MMMM-yyyy';
  DateTimePicker1.Perform(DTM_SETFORMAT, 0, DWORD(sFormat));
end;

// Show the Week Number in a TDateTimePicker

procedure DateToWeek(dtDate: TDateTime; var AWeek, AYear: Word);
const
  
FIRST_WEEKDAY: Integer = 2;
  FIRST_WEEKDATE: Integer = 4;
var
  
wMonth, wDay: Word;
begin
  
dtDate := dtDate - ((DayOfWeek(dtDate) - FIRST_WEEKDAY + 7) mod 7) + 7 - FIRST_WEEKDATE;
  DecodeDate(dtDate, AYear, wMonth, wDay);
  AWeek := (Trunc(dtDate - EncodeDate(AYear, 1, 1)) div 7) + 1;
end;

procedure TForm1.DateTimePicker1Change(Sender: TObject);
var
  
sFormat: string;
  wWeek, wYear: Word;
begin
  
DateToWeek(DateTimePicker1.date, wWeek, wYear);
  sFormat := 'dd/MM/yy Week:' + IntToStr(wWeek) + '';
  DateTimePicker1.Perform(DTM_SETFORMAT, 0, DWORD(sFormat));
end;

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


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners