Re: DateTime.Now.ToString("t") not printing what I expect

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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 (wawang@xxxxxxxxxxxxxxxxxxxx, 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.

.



Relevant Pages

  • Re: DateTime.Now.ToString("t") not printing what I expect
    ... the settings can be found at the user's registry key ... Based on what account your ASP.NET web application is running at, ... I'm not sure by means of "I want it to follow the current culture ... you can first find its SID using PsGetSid and look at ...
    (microsoft.public.dotnet.framework)
  • Re: Should programs install to All Users, Default User, or Me?
    ... > ...where you have to duplicate settings to each account by hand. ... well - - - everything visible in Admin as I have in woody! ... For now I reset the basics and log'd out of admin and back into woody, ...
    (microsoft.public.windowsxp.general)
  • Update has created havoc
    ... Settings" and then copy everything from one account to the other. ... profile after creating a new user. ... data that I had under my original user. ...
    (microsoft.public.windowsupdate)
  • Re: Problem: New Identity Changes Settings on Main Identity
    ... > In my example the "Alan" identity is the main identity. ... >>> Account Name: alan@alansdomain.com ... >>> Now I want to add an additional identity for "Bill". ... I find that Alan's settings are now all changed to ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Can you back up mail account settings in Outlook 2007?
    ... Thank you for clarifying about the registry key paths etc. ... its original factory settings, in order to determine whether an issue I have ... Outlook Express did- but it is not the same program as Outlook. ... two letters of every password for every account on both profiles. ...
    (microsoft.public.outlook)