Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DateFormat and Culture
Message
 
À
10/03/2016 06:43:38
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
ASP.NET
Divers
Thread ID:
01632723
Message ID:
01633001
Vues:
57
>Thanks Rick, someone had pointed out your blog and I had gone through it already. Your code seems to pull the settings from the System Locale rather than the Regional short date format. SO for instance I could have my region set to Trinidad and Tobago which uses dd/mm/yyyy as the short date format, but the System locale could be set to "en-us" (I was completely unaware of this setting until I used your code). I don't think many people are aware of that. Or maybe I am just seeing weird results.

You don't need to use a special locale. If you always want the date set a certain way you can create a new locale for the locale you want to work with and simply set the appropriate properties on the DateFormat object. Note this only works when you create a new Locale object as the initial locales passed are static and cached.

As to using string dates: There are lots of advantages to that:

* Easier to parse to the eye (athough not so good in lists/tables)
* Non-ambiguous
* More appropriate if you don't translate your site

It's really funky if you display the date format in European format, but your Web site is an American site displaying everything in English. Even if you switch or don't switch, it's never really obvious to the foreigh user if the date format is theirs or the US one. So whenever possible I opt for string dates and in .NET that's super easy to do.

You can also look at Humanizer which includes dates as friendly strings (yesterday, today, a few hours ago, a month ago etc.) and which can do things like pluarizing, and numbers to string etc. Great library but if you use multiple locales requires satellite assemblies for each locale supported.

+++ Rick ---

>
>I do like your idea of displaying the month in words to get rid of all ambiguity.
>
>>You can sniff the browser's languages and based on that automatically switch that local. Best to do this in Application_BeginRequest of each request.
>>
>>You'll probably want to be careful not to actually support all languages for translation (UICulture), but you might want to support all the culture information (Culture) for date and number formats.
>>
>>You can also override specific settings explicitly by creating a new Culture object for a specific locale and hten overriding any values. For example, I like to override the currency symbol and set it to a $ because I only sell stuff in US dollars regardless of the user's culture. Yet I allow people to see dates and
>>numbers in their culture specific formats.
>>
>>I have a related blog post that discusses selecting cultures and overriding some values (I typically override the currency symbol because I charge in $ regardless of locale).
>>
>>https://weblog.west-wind.com/posts/2014/Mar/27/Auto-Selecting-Cultures-for-Localization-in-ASPNET
>>
>>All that said, for dates I much prefer NOT using numbers but using things Oct 10, 2015 or things like Yesterday, last week etc. These things are usually much better at showing the values wihtout the positioning ambiguity. Something to consider.
>>
>>
>>+++ Rick ---
>>
>>>Hi,
>>>
>>>using C# and ASP.NET for a web site. When I run the stuff locally, my dates display in dd/mm/yyyy format which is what I want. When I install it on a web server which has its date formatting set to mm/dd/yyyy the web pages display dates in mm/dd/yyyy format.
>>>
>>>What I would like is the dates to display in the format set on the PC that is accessing the web site. I am using DevExpress and their advice was to use this:
>>>
>>>
        protected void Page_Load(object sender, EventArgs e)
>>>        {
>>>            (ASPxGridViewMain.Columns["Timestamp"] as GridViewDataDateColumn).PropertiesDateEdit.DisplayFormatString = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
>>>        }
>>>
>>>
>>>This doesn't seem to be working.
>>>
>>>Any suggestions as to how to get this to work?
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform