Motaz
asked on
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 ?
Make sure that your Windows settings are setup to use the 24 hour clock rather than the 12 hour one
The Neil
The Neil
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(TFo rm1, Form1);
Application.Run;
ShortTimeFormat:=TmpS;
LongTimeFormat:=TmpL;
end.
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(TFo
Application.Run;
ShortTimeFormat:=TmpS;
LongTimeFormat:=TmpL;
end.
ASKER
I try it but it didn't work. It works only with DateTimeToString function, but it did not affect DateTimePicker
Motaz
Motaz
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.
Did you actually put it in the Project Source Code? (It has to be implemented before the controls are created - I think.)
John.
ASKER
Did you check it with DateTimePicker ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hello
did you try ?
did you try ?
ASKER
Yes it didn't work, I need a 24 hour format for a DateTimePicker and no thing else
Motaz
Motaz
ASKER
Thanks Barry, it works.Thanks for your great help
ASKER