Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I Wrote some code in C# winforms to change system date format. When I run that, It is changing the format but not quickly. It is taking some time to change the format like maximum time one minute and minimum time depending on the seconds to change the next minute. When minute is changing that format is changing. But I need to change that format quickly.

here my code

private void changedate()
        {
            
            
            RegistryKey regkey = Registry.CurrentUser.OpenSubKey(@"Control Panel\International", true);
            regkey.SetValue("sShortDate", "dd-MM-yyyy");
            regkey.SetValue("sLongDate", "dd-MM-yyyy");
            
        }


What I have tried:

I googled for the solution but failed
Posted
Updated 13-Apr-23 15:00pm
v2
Comments
OriginalGriff 11-Apr-23 8:15am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

Use the "Improve question" widget to edit your question and provide better information.
vijay_bale 11-Apr-23 8:22am    
I developed a billing app in that that date format is required. in some clients systems that date format maybe in other like yyyy-MMMM-dddd or any other. But we won't take that. so when ever I ran this I just changing the date format to dd/MM/yyyy which is our country/region format. For that purpose only I wrote this one not as part of that project but individual one.
Richard MacCutchan 11-Apr-23 11:10am    
There is something very wrong with your application if you need to change Registry settings to make it work.
Dave Kreskowiak 11-Apr-23 8:19am    
Are you saying that when you change the format string in the registry, Windows does not reflect that change immediately?

And why are you even doing this? This changes the format SYSTEM WIDE, not just for a single application.
vijay_bale 11-Apr-23 8:36am    
That is the format of our country/region. Some hardware people, after formatting system they don't change the system date format. 4% of my clients like that only.

Are you crazy?
You are changing the date format for the whole system just so your app "works"? Do you have any idea how much that will annoy your users, and potentially damage all their other systems database integrity?

System settings for locale are set by the user, for the user - because that is what they are happy using and expect to input in.

Don;t mess with system settings at all - use the current locale as set by the user and process dates entered based on that, or use Calendar based controls so the user can enter it in his preferred format any you just get a DateTime value directly.

If an app did that on my system, it would be uninstalled with extreme prejudice, and I'd be looking for my money back, if not compensation for any data damage it may have caused to other apps.
 
Share this answer
 
v2
Comments
vijay_bale 11-Apr-23 9:17am    
I am changing this because some people are not changing. That is our Country's(India) format. They are not changing because some other softwares not working properly of this problem so they are changing when ever they are loading like unilever, dabur and other companies. At loading time they are checking and if wrong format detected they are changing. This format only running in government offices and other places. curreny only that hardware people are changing because currency not changing then calculation will go wrong. our curreny is rupee in system they are changing that from dollor to rupee.
There are several ways to control input of dates in .net. As noted above you can use calendars. You can also parse dates and checking for max numbers (it is not perfect, but you can probably prevent most errors). You can enter date with three controls and checking entries.
You can also use a MaskedTextBox control or similar third-Party products.

MaskedTextBox Class (System.Windows.Forms) | Microsoft Learn[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900