954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Changing Time format

Hi All
I want to change format of system Time display by my program
for example if format of system time is "hh:mm:ss AM"(12 hour clock format) I want to change it to "HH:mm:ss"(24 hour clock format)
is any solution for this purpose?
thanks

fayyaz
Junior Poster in Training
66 posts since Jun 2007
Reputation Points: 12
Solved Threads: 10
 

Do you mean that you want to show a clock on your app? And you want to format the time in some way other than TimeToStr() ?

If so then use the following from sysutils:
function FormatDateTime(const Format: string;
DateTime: TDateTime): string;

If the format is hh:nn:ss it will use 24 hour time.

I hope that helps,

Mark

Delphic
Newbie Poster
3 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

thankyou my frend
it is a good method for changing time format
but i need to an instruction that change format of system time that runing application be caus to changing windows time format

fayyaz
Junior Poster in Training
66 posts since Jun 2007
Reputation Points: 12
Solved Threads: 10
 
thankyou my frend it is a good method for changing time format but i need to an instruction that change format of system time that runing application be caus to changing windows time format

You must to use SetLocaleInfo function from Win32 API.


ex.:

procedure SetTimeFormat(tfType24 :Boolean)
var
  Changed :Boolean;
  LCID :LongInt;
begin
  LCID := GetSystemDefaultLCID;
  if ftType24 then  // if format type is 24 hours...
    Changed := SetLocaleInfo(LCID, LOCALE_STIMEFORMAT, 'HH:mm:ss')
  else  // if format type is 12 hours AM/PM
    Changed := SetLocaleInfo(LCID, LOCALE_STIMEFORMAT, 'hh:mm:ss');

   if Changed then  // if no error then notify all app that settings changed
     SendMessage(HWND_TOPMOST, WM_SETTINGCHANGE, 0, 0);
 end;



bye.

Micheus
Junior Poster in Training
72 posts since Jun 2006
Reputation Points: 10
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You