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 ?
LVL 7
MotazAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.