Change date format in en-us, and culture - fr-ca

I am working on localizing a website in French. However, I should not change the date format to French. It must remain in en-us format, even if the culture is set to fr-ca ie, when the rest of the content is in French, the date format must remain in English (en-us).

+9
c # internationalization
source share
6 answers

Surprisingly, I got a very simple answer. Having installed Culture and UICulture, all I have to do is always establish Cultural Property. This will permanently display the date format in English.

+1
source share

To change the date format, you can create a custom CultureInfo configuration based on the existing CultureInfo (in your case "fr-CA"), changing only the date formats. I have no experience with this, but the related article and this article explain how this is done. This is supposedly not too complicated.

I assume that setting System.Threading.Thread.CurrentThread.CurrentCulture instance of your custom CultureInfo object (for example, in the Page.Load event) should do the job.


Or use the CultureInfo class to specify culture by line:

 CultureInfo culture = new CultureInfo("en-US"); 

Whenever you write a date on a page, use the following syntax:

 myDate.ToString("d", culture); 

or

 string.Format( culture, "This is a string containing a date: {0:d}", myDate); 

The CultureInfo class is in the System.Globalization namespace, and d in the above format is the date output format. For more information about format strings, see the "Crib" section in the .NET.NET String Quick Reference format .

+9
source share

In my case, I had to install the application language, and also determine whether the language is right to left, but I also need to keep the standard date and time format. Here is what I did:

 string culture = "ar-SA"; //Set language and culture to Arabic Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culture); //But independent of language, keep datetime format same DateTimeFormatInfo englishDateTimeFormat = new CultureInfo("en-CA").DateTimeFormat; Thread.CurrentThread.CurrentCulture.DateTimeFormat = englishDateTimeFormat; 
+3
source share

In the line when displaying the date, do the following:

 CultureInfo ci = new CultureInfo("en-US"); string s = dateTimeObject.ToString(ci); 

However, this is a simplified example, you just need to do the necessary work on the DateTime object.

+2
source share

Thanks guys!!!! Your sanctions seem to work for me. I tried to create a custom culture that extends fr-ca and changes the date format to en-us. Here is the code

 CultureInfo ci = new CultureInfo("fr-ca"); DateTimeFormatInfo dateformat = new DateTimeFormatInfo(); dateformat.FullDateTimePattern = "dddd, mmmm dd, yyyy h:mm:ss tt";// Date format of en-us ci.DateTimeFormat = dateformat; CultureAndRegionInfoBuilder obj = new CultureAndRegionInfoBuilder("fr-ca", CultureAndRegionModifiers.Replacement); obj.LoadDataFromCultureInfo(ci); obj.Register(); 

As soon as the code registers the new fr-ca, the date format for fr-ca will be the same as for en-us. The code can be used in Page_Load.

+2
source share

Here is the above code in snipet code:

 CultureInfo ci = new CultureInfo("fr-ca"); DateTimeFormatInfo dateformat = new DateTimeFormatInfo(); dateformat.FullDateTimePattern = "dddd, mmmm dd, yyyy h:mm:ss tt";// Date format of en-us ci.DateTimeFormat = dateformat; CultureAndRegionInfoBuilder obj = new CultureAndRegionInfoBuilder("fr-ca", CultureAndRegionModifiers.Replacement); obj.LoadDataFromCultureInfo(ci); obj.Register(); 
+1
source share

All Articles