Changing Date format to en-us while culture is fr-ca

后端 未结 6 599
[愿得一人]
[愿得一人] 2021-01-11 17:21

I\'m working on localizing a website in French. However I am not supposed to change the date format to French. It must remain as per en-us format even if the culture is set

6条回答
  •  情话喂你
    2021-01-11 18:14

    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;
    

提交回复
热议问题