User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 455,993 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,798 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 2817 | Replies: 10
Reply
Join Date: Jun 2007
Location: Iran
Posts: 19
Reputation: fayyaz is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
fayyaz fayyaz is offline Offline
Newbie Poster

Help Changing system Time Format

  #1  
Dec 5th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Changing system Time Format

  #2  
Dec 5th, 2007
Are you talking about Delphi's ShortDateFormat /ShortTimeFormat /LongDateFormat /LongTimeFormat variables (in SysUtils)?

Or are you talking about changing something in the OS?
Reply With Quote  
Join Date: Jun 2007
Location: Iran
Posts: 19
Reputation: fayyaz is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
fayyaz fayyaz is offline Offline
Newbie Poster

Re: Changing system Time Format

  #3  
Dec 20th, 2007
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
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: Changing system Time Format

  #4  
Dec 20th, 2007
Originally Posted by fayyaz View Post
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.
Reply With Quote  
Join Date: Jun 2007
Location: Iran
Posts: 19
Reputation: fayyaz is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
fayyaz fayyaz is offline Offline
Newbie Poster

Re: Changing system Time Format

  #5  
Dec 20th, 2007
Thankyou very much "ExplainThat "
whold you please send me a simple Example code for using registry Object?
Thankyou
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: Changing system Time Format

  #6  
Dec 20th, 2007
Originally Posted by fayyaz View Post
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.
Reply With Quote  
Join Date: Jun 2007
Location: Iran
Posts: 19
Reputation: fayyaz is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
fayyaz fayyaz is offline Offline
Newbie Poster

Re: Changing system Time Format

  #7  
Dec 20th, 2007
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
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Changing system Time Format

  #8  
Dec 20th, 2007
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:
  1. var
  2. shelltraywnd, traynotifywnd, clockwnd: HWND;
  3. begin
  4. shelltraywnd := FindWindowEx( 0, 0, 'shell_traywnd', nil );
  5. traynotifywnd := FindWindowEx( shelltraywnd, 0, 'traynotifywnd', nil );
  6. clockwnd := FindWindowEx( traynotifywnd, 0, 'trayclockwclass', nil );
  7. SendMessage( clockwnd, WM_PAINT, 0, 0 )
  8. end;
Let us know if that doesn't work.
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: Changing system Time Format

  #9  
Dec 21st, 2007
Originally Posted by Duoas View Post
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:
  1. var
  2. shelltraywnd, traynotifywnd, clockwnd: HWND;
  3. begin
  4. shelltraywnd := FindWindowEx( 0, 0, 'shell_traywnd', nil );
  5. traynotifywnd := FindWindowEx( shelltraywnd, 0, 'traynotifywnd', nil );
  6. clockwnd := FindWindowEx( traynotifywnd, 0, 'trayclockwclass', nil );
  7. SendMessage( clockwnd, WM_PAINT, 0, 0 )
  8. 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 using
  • Change 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.
Last edited by ExplainThat : Dec 21st, 2007 at 3:24 am.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Changing system Time Format

  #10  
Dec 21st, 2007
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).
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 9:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC