Thanks Larry for your input.
Hi Eric,
As Larry tested in the code, the ShortTimePattern is not read from the
Control Panel's Regional and Language Options. The time format is actually
LongTimePattern's default value in .NET DateTimeFormatInfo. You can get all
supported cultures' ShortTimePattern by following code:
foreach(CultureInfo ci in
CultureInfo.GetCultures(CultureTypes.AllCultures))
{
if (!ci.IsNeutralCulture)
Console.WriteLine("{0}\t{1}\t{2}", ci.Name,
ci.DateTimeFormat.ShortTimePattern, ci.DateTimeFormat.LongTimePattern);
}
The DateTime format set in Control Panel's Regional and Language Options is
user-specific, the settings can be found at the user's registry key
"HKEY_CURRENT_USER\Control Panel\International", you will find
"sShortDate", "sLongDate", "sTimeFormat", etc.
Based on what account your ASP.NET web application is running at, the
account's settings will be used as default date time format
(LongTimePattern, LongDatePattern, ShortDatePattern, etc). If you are using
the File System mode to run/debug web application, it's running using your
current logon user account, thus takes current regional settings in control
panel into account. If you're using IIS mode to run/debug web application,
it's running using ASP.NET worker process account ('NETWORK SERVICE' if on
IIS6/Win2003, 'ASPNET' if on IIS5.x), thus only those accounts' settings
will be used as the default values.
This is all about using default settings, you can override this behavior by
explicitly set a culture in machine.config or web.config:
<globalization culture="en-US" ...
I'm not sure by means of "I want it to follow the current culture
settings", do you mean use the current culture on the system which is
running the ASP.NET web application, or the client that is visiting your
web application? Because ASP.NET 2.0 has a great feature called "auto
culture", when turned on, each user visiting your web application will use
his/her culture settings when browsing your web application. To turn on
this feature, either in web.config:
<globalization culture="auto" ...
or in individual page directive:
<@ page culture="auto" ...
By the way, if you want to know which regional settings that the 'NETWORK
SERVICE' or 'ASPNET' account is using (since you cannot logon locally using
these accounts), you can first find its SID using PsGetSid and look at
"HKEY_USERS\<sid>\Control Panel\International".
#PsGetSid
http://www.sysinternals.com/Utilities/PsGetSid.html
Use 'psgetsid ASPNET' or 'psgetsid "Network Service"' to get the SID of
ASP.NET worker process account.
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.