DateTime Difference on WinForm and WebForm!  
Author Message
Peter Peng





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

I write a simply code to see the difference:

this.label1.Text = DateTime.Now.ToString();

this.label1.Text +=" "+ System.Globalization.CultureInfo.CurrentCulture.ToString();

The output of WinForm is “28/11/2006 11:03:21 en-GB”, while WebForm is “11/28/2006 11:02:55 AM en-US”.

Even I restart my computer, the difference is still on.

Can you explain this difference




Visual C#14  
 
 
SvenC





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

You installed a US-english version of Windows which makes en-us the default locale. In your logon user session you changed the locale to en-GB, so that effects your WinForm app. The WebForm runs in another account (win2003 will use NETWORK SERVICE by default, Win2000 ASPNET).

Check your Regional Settings control panel settings. You should find some point where you can change the system default.

--
SvenC


 
 
Ajeeth Kumar





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

hi

Is the Web service runnin in the same machine where your Windows client is running..

If its a separate web server then check the region settings for date in the server.

Regds,



 
 
Peter Peng





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

WinForm and WebForm deployed in the same computer.

I have changed the local language settings, but ever restart the iis and restart my computer, the difference is still on.

What can I do to make the WebForm Application confirm to the new local language settings

Thanks!



 
 
Peter Peng





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

Thanks for you reply.

Yes, why I turn to such trival issue is that I met a bug in my code.

Maybe several days ago, the bug found in my code,

string ss=DateTime.Now.ToString(); // in en-US way "mm-dd-yyyy"

DateTime dt=DateTime.Parse(ss); // the bug happened, because it parsed in en-GB way "dd-mm-yyyy"

But After I changed the local language settings to en-US, and change back to en-GB, I can't repro this bug anymore. Because whatever language I changed to, it confirm to the way of en-US.



 
 
SvenC





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

What Windows version are you using How did you change the local settings. Please post the exact steps.

--
SvenC


 
 
SteveDrake





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

You can change the culture for ASP.NET by :

Using regional settings, try changing the system setting.

Edit Web.Config or Machine.Config :

<configuration>

<system.web>

<globalization

culture="en-US"

uiCulture="de-DE"

/>

</system.web>

</configuration>

You can edit the aspx.

Or with code

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(Request.UserLanguages[0]);

This should be what you need todo, you should not change server settings alter the culture unless you have a good reason todo this, read the users setting.

Hope this helps.

Steve

http://stevesdotnetblog.spaces.live.com/


 
 
Peter Peng





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

Yes, I think your suggestion will help.

But I want to know how to change the settings of computer to change the WebApp's default culture.

From "Regional and Language Options", whatever kind of culturen I changed to, the WebApp confirm to "en-US" culture, only the WinFormApp's culture changed.

Thanks.



 
 
SteveDrake





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

You may have an issue, if you change the system defaults to another LANG then anything that runs as local system will adopt the new settting. Any new accounts will also adopt the setting.

Is you webapp in its own application pool with its own users if it is, it will use the LANG settings from that users.

If its running as the default application pool it will probs be running as the account Network Service.

So, you may need to the settings for this account.

The SID for this account is S-1-5-20, so look in :

HKEY_USERS\S-1-5-20\Control Panel\International

YOUR settings should be at

HKEY_CURRENT_USER\Control Panel\International

I have just tried this on my test server and it worked, so, your step by step guide is :

Use Control Panel -> Regional Settings

Adjust setting if needed.

Under the Advanced, select Apply all settings to the current user account and the default user profile, click ok.

Run regedit edit

Export [HKEY_CURRENT_USER\Control Panel\International] to a file

Open this file in notepad, change :

[HKEY_CURRENT_USER\Control Panel\International]

and

[HKEY_CURRENT_USER\Control Panel\International\Geo]

to

[HKEY_USERS\S-1-5-20\Control Panel\International]

and

[HKEY_USERS\S-1-5-20\Control Panel\International\Geo]

Import this file, run IISRESET, things should work.

It worked for me, let me know if it works for you.

Thanks

Steve


 
 
Peter Peng





PostPosted: Visual C# General, DateTime Difference on WinForm and WebForm! Top

Thank you very much.

I got the solution now.