• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3457
  • Last Modified:

24 Hour format for Date time picker

I use DateTimePicker component, Time mode. I want to set it's time format to 24 hour time format. How can I do this ?
0
Motaz
Asked:
Motaz
  • 5
  • 2
  • 2
  • +1
1 Solution
 
MotazAuthor Commented:
also I want to change time format of TeeChart (in QuickReport) to 24 hour format.
0
 
TheNeilCommented:
Make sure that your Windows settings are setup to use the 24 hour clock rather than the 12 hour one

The Neil
0
 
JaymolCommented:
You can use the ShortDateFormat system variable to achieve this.  In the project source, store the initial setting for the variable in one of your own, set the 24hr type, and then restore at the end of the program.  Like this...

program Project1;

uses
  Forms, SysUtils,
  Unit1 in 'Unit1.pas' {Form1};

var
  TmpS : String;
  TmpL : String;
begin
  TmpS:=ShortTimeFormat;
  ShortTimeFormat:='24hh:mm';
  TmpL:=LongTimeFormat;
  LongTimeFormat:='24hh:mm';
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
  ShortTimeFormat:=TmpS;
  LongTimeFormat:=TmpL;
end.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
MotazAuthor Commented:
I try it but it didn't work. It works only with DateTimeToString function, but it did not affect DateTimePicker

Motaz
0
 
JaymolCommented:
I'm afraid I can't help you then, cos that works for me!  It makes EVERYTHING that uses time 24hr and resets it later to the original Windows setting.

Did you actually put it in the Project Source Code?  (It has to be implemented before the controls are created - I think.)

John.
0
 
MotazAuthor Commented:
Did you check it with DateTimePicker ?
0
 
intheCommented:
HI motaz
please try these:
(upper/lowercase matters)

//Uses Commctrl;
procedure TForm1.FormCreate(Sender: TObject);
begin
SendMessage(DateTimePicker1.Handle,DTM_SETFORMAT, 0,LongInt(PChar('HH:mm:ss')));

//The format strings are what Windows allows in the Regional
// Settings for Time -  "HH" is military (24h time) and
//"hh" is 12 hour, adding "tt" to the end gets you the "am" / "pm", etc.

end;

//or with date and am/pm also:
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMessage(DateTimePicker1.Handle,DTM_SETFORMAT, 0,LongInt(PChar('dd/MM/yyyy HH:mm:ss tt')));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Application.UpdateFormatSettings := False;
ShortTimeFormat := 'HH:mm:ss';
end;

Regards Barry
0
 
intheCommented:
hello
did you try ?
0
 
MotazAuthor Commented:
Yes it didn't work, I need a 24 hour format for a DateTimePicker and no thing else

Motaz
0
 
MotazAuthor Commented:
Thanks Barry, it works.Thanks for your great help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now