Changing Date format to en-us while culture is fr-ca
To change how dates are formatted you could create a custom CultureInfo, based on an existing CultureInfo (in your case "fr-CA"), modifying only the date formats. I don't have any experience in this, but the linked aricle and this article explains how it's done. Supposedly, it's not too difficult.
I imagine that setting System.Threading.Thread.CurrentThread.CurrentCulture
to an instance of your custom CultureInfo (e.g. in the Page.Load event) should do the job.
Or, use the CultureInfo class to specify culture on a per-string basis:
CultureInfo culture = new CultureInfo("en-US");
Whenever you write a date to the 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 resides in the System.Globalization
namespace and d
in the above is the format in which to output the date. See John Sheehan's ".NET Format String Quick Reference" cheat sheet for more on format strings.
Thanks Guys !!!! Seems like your sugessions are working for me. I tried creating a custom culture which extends the features of fr-ca and changes its 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();
Once the code registers new fr-ca, the date format of the fr-ca will be same as that of en-us. The code can be used in Page_Load.
In my case I had to set the language of the app, also determine if the language is right-to-left language, but also needed to keep the standard datetime format. So that was 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;