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 system Time Format

Hi All

how can I change System time format From hh:mm:ss(12 Hour) to HH:mm:ss(24 Hour) Using Delphi code?
Thanks

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

Are you talking about Delphi's ShortDateFormat /ShortTimeFormat /LongDateFormat /LongTimeFormat variables (in SysUtils)?

Or are you talking about changing something in the OS?

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

Dear Duas
Thankyou for Your Answer.
about your question I mast Say No I want to changing format of OS time by sume Delphi instructions

fayyaz
Junior Poster in Training
66 posts since Jun 2007
Reputation Points: 12
Solved Threads: 10
 
Dear Duas Thankyou for Your Answer. about your question I mast Say No I want to changing format of OS time by sume Delphi instructions

One way would be to change the Windows Registry settings directly. The entries you are looking for are the sLongDate, sShortDate and sTimeFormat strings under HKEY_CURRENT_USER\Control Panel\International. You can use the Delphi TRegistry object to manipulate these entries.

ExplainThat
Junior Poster in Training
69 posts since Sep 2007
Reputation Points: 32
Solved Threads: 7
 

Thankyou very much "ExplainThat "
whold you please send me a simple Example code for using registry Object?
Thankyou

fayyaz
Junior Poster in Training
66 posts since Jun 2007
Reputation Points: 12
Solved Threads: 10
 
Thankyou very much "ExplainThat " whold you please send me a simple Example code for using registry Object? Thankyou

End of my working day here so a detailed example will have to wait for tomorrow. If you really want to have a go at it right away just take a look at the TRegistry object methods in Delphi help. Your code would go something like this

with TRegistry.Create(Self) do
try
  OpenKey(...);
  //modify key contents here
finally Free end;


Quoting from memory so there might be errors. TRegistry is not hard to play with so you might find that the examples in Delphi Help sufficient. Do post a message saying if you have managed on your own so I don't end up spending time telling what you already know.

ExplainThat
Junior Poster in Training
69 posts since Sep 2007
Reputation Points: 32
Solved Threads: 7
 

Thankyou "ExplainThat "
I write Same code And I can Change Registry
But I mast restart computer after runing code for making effect on time Format
is any way that dont need to restart system
Thanks

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

I've never done it, but I think you just need to tell the tray to repaint itself.
You should be able to do it with something like the following:

var
  shelltraywnd, traynotifywnd, clockwnd: HWND;
begin
  shelltraywnd := FindWindowEx( 0, 0, 'shell_traywnd', nil );
  traynotifywnd := FindWindowEx( shelltraywnd, 0, 'traynotifywnd', nil );
  clockwnd := FindWindowEx( traynotifywnd, 0, 'trayclockwclass', nil );
  SendMessage( clockwnd, WM_PAINT, 0, 0 )
end;

Let us know if that doesn't work.

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

I've never done it, but I think you just need to tell the tray to repaint itself. You should be able to do it with something like the following:

var
  shelltraywnd, traynotifywnd, clockwnd: HWND;
begin
  shelltraywnd := FindWindowEx( 0, 0, 'shell_traywnd', nil );
  traynotifywnd := FindWindowEx( shelltraywnd, 0, 'traynotifywnd', nil );
  clockwnd := FindWindowEx( traynotifywnd, 0, 'trayclockwclass', nil );
  SendMessage( clockwnd, WM_PAINT, 0, 0 )
end;

Let us know if that doesn't work.

I am almost certain that works. In case it does not, here is a trick I remember usingChange the registry strings
Use the Windows GetLocalTime function to fetch the current time in a SystemTime structure.
Sleep(1)
Call Windows SetLocalTime using the SystemTime data obtained above.

I remember doing this but not with WindowsXP. Seem to recall that I did a Sleep(1) to ensure that Windows recognized that the time was in fact different.

This is nothing short of a cheap hack. Try the tray repaint technique first.

ExplainThat
Junior Poster in Training
69 posts since Sep 2007
Reputation Points: 32
Solved Threads: 7
 

Ah, glad I wasn't completely off in left field. I was sure ExplainThat had a better clue here than I...

The sleep() is required to give the registry time to update (it isn't absolutely instantaneous).

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 
I write Same code And I can Change Registry But I mast restart computer after runing code for making effect on time Format is any way that dont need to restart system


I'm have answered this question for You last July. Doesn't You remember? ( post )

It was a procedure called SetTimeFormat with a litle compiler error (it's true): the parameter was bad named.
But, you don't reply or report me this mistake, and I don't have perceived: I had put tfType24 but must be ftType24.

procedure SetTimeFormat(ftType24 :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;


This procedure work right to me.
No access to register and no computer restart are necessary.

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