cultureinfo

How to get country name

懵懂的女人 提交于 2019-12-04 16:04:56
问题 I used the code below to get the list of culture type, is there a way on how to get just the country name? Thank you static void Main(string[] args) { StringBuilder sb = new StringBuilder(); foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { sb.Append(ci.DisplayName); sb.AppendLine(); } Console.WriteLine(sb.ToString()); Console.ReadLine(); } Sample Output: Spanish (Puerto Rico) Spanish (United States) 回答1: Well, this regular expression seems to do the job in

WPF Default DateTime format

匆匆过客 提交于 2019-12-04 14:17:18
Working on a large WPF application and having some issues with the DateTime format, it's a huge codebase and many places do not specify the culture. When the user opens the application on Windows 7 or 8 the datetime format is different (Win 7 uses slashes and Win 8 uses dashes). I tried setting the Culture to "en-US" in the Application Startup (see below link) but it doesn't seem work? Setting Culture (en-IN) Globally in WPF App How do I set my WPF application to not use the culture of the user machine? kmcnamee Here is what I use in OnStartup . It's different than the SO question you linked

Installing more cultures on Windows Server 2012

孤者浪人 提交于 2019-12-04 09:28:52
On a Windows 8.1 machine, I'm seeing many more available cultures than on a Windows Server 2012 machine: 791 vs 378. To give a specific example, the server machine is missing the 'en-HK' culture. Here is the test code I'm using to enumerate them: foreach (var ci in CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures).OrderBy(ci => ci.Name)) { Console.WriteLine("{0} ({1})", ci.Name, ci.EnglishName); } Question: how can I install the more complete culture list on Windows Server 2012 so that it matches what's available on Windows 8.1? Here's some Powershell I've used to add

Passing a DateTime to controller via URL causing error in ASP .NET MVC 3 (culture)

最后都变了- 提交于 2019-12-04 08:34:05
问题 My application is setted with pt-BR culture (Date is dd-mm-yyyy) in web.config: <globalization enableClientBasedCulture="false" requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="iso-8859-15" responseHeaderEncoding="utf-8" resourceProviderFactoryType="string" enableBestFitResponseEncoding="true" culture="pt-BR" uiCulture="pt-BR" /> All DateTime created on my system is in right format, but I created a controller method like that: public ActionResult Test(DateTime date) { } Calling

How to make DateTime independent from the current culture?

两盒软妹~` 提交于 2019-12-04 07:16:16
I cam trying to convert a datetime to string and back, but making it so that it works for all cultures. I basically have a Textbox (tbDateTime) and a label (lbDateTime). The label tells the user, in which format the software expects the input of tbDateTime. The input of the Textbox will be used for an MySQL command. Currently it works like this: lbDateTime.Text = "DD.MM.YYYY hh:mm:ss"; // I live in germany DateTime date = Convert.ToDateTime(tbDateTime.Text); String filter = date.ToString("yyyy-MM-dd HH:mm:ss"); Now my question: Is it possible to determine the format-string for lbDateTime.Text

Replace dot(.) with comma(,) using RegEx?

旧巷老猫 提交于 2019-12-04 06:19:49
I am working on a C# application. I want to change number decimal figure with comma(,) where i have dot(.) using regular expression. For example: Price= 100,00.56 As this international rule of representing numeric values but I Sweden they have different ways for numbers Like Price= 100.00,56 So i want to change dot(.) into comma(,) and comma(,) into dot(.) using RegEx. Could guide me about this. When formatting numbers, you should use the string format overload that takes a CultureInfo object. The culture name for swedish is "sv-SE", as can be seen here . decimal value = -16325.62m; Console

C# and Current Local time for different countries

牧云@^-^@ 提交于 2019-12-04 05:05:57
C# offers a way to get the current date by DateTime.Now . But the problem is my server is on US and I get the US time when I use DateTime.Now Is there any way to get the current local time for a specific country in C# as my users are from around the world? (I have locale of each user, so if I Can get the current time for each locale then I’m safe) I've seen a way using Time Zone but then I have to keep time zone vs country reference. I’ve searched and most of the question here is about converting UTC time to local time and vice versa. Hope someone would be able to enlighten me. Dan Hunex Save

How to format double without fractional part

守給你的承諾、 提交于 2019-12-04 04:58:08
问题 The value am sending is 100233 double value = 100233; string a = (value.ToString("N", CultureInfo.InvariantCulture)); output 100,233.00 but i want 100,233 i don't want the trailing zeros . Is there any specific way to get it ? 回答1: you are close double value = 100233; string a = (value.ToString("N0", CultureInfo.InvariantCulture)); 来源: https://stackoverflow.com/questions/17058182/how-to-format-double-without-fractional-part

ASP.NET Globalization: Culture=“auto” page directive with neutral culture crash?

别等时光非礼了梦想. 提交于 2019-12-04 04:11:27
I'm running into a case where an ASP.NET application using the built-in globalization facilities is crashing. On an ASP.NET page with the Culture="auto" directive, a user with a neutral culture as their browser language (such as "zh-Hans") will produce the following exception: Culture 'zh-Hans' is a neutral culture. It cannot be used in formatting and parsing and therefore cannot be set as the thread's current culture. at System.Globalization.CultureInfo.CheckNeutral(CultureInfo culture) at System.Threading.Thread.set_CurrentCulture(CultureInfo value) at System.Web.UI.Page.set_Culture(String

Setting culture for session

谁说我不能喝 提交于 2019-12-04 03:58:45
问题 Each user of my application will choose their country, after which it will be stored in a cookie and stored for later requests. Everything is working OK, but I need to set the culture at the start of a session. I'm currently experimenting by setting the culture in the web.config to be en-GB and then using the Global.asax to override the culture for the session to en-US. Code below protected void Session_Start(object sender, EventArgs e) { if (Globals.CountryID == 8) { Thread.CurrentThread