cultureinfo

DateTime.ParseExact() does not grok 24-hour time values?

大兔子大兔子 提交于 2019-11-27 06:42:06
问题 This line of code: DateTime dt = DateTime.ParseExact(time, "hh:mm", CultureInfo.InvariantCulture); parses a "time" value of "12:45" just fine, but throws an exception of "13:00" Should I be using some other CultureInfo value, or do I need to append a "pm" to hour values above 12, or ... ? Error message is: System.FormatException was unhandled Message=String was not recognized as a valid DateTime. 回答1: "hh" is the 12-hour clock format (01 to 12). You need to use "HH" for a 24 hour clock.

how to set default culture info for entire c# application

喜你入骨 提交于 2019-11-27 05:35:26
问题 I want to set default culture info for that class or for entire application. For example in Turkey 3,2 = in english 3.2 so application uses my local but i want it to use as default System.Globalization.CultureInfo.InvariantCulture How can i set it to that as default for that specific class or for entire application 回答1: Not for entire application or particular class. CurrentUICulture and CurrentCulture are settable per thread as discussed here Is there a way of setting culture for a whole

How to get current regional settings in C#?

▼魔方 西西 提交于 2019-11-27 04:46:54
Normally you can get it by writing something like CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; But this way you can only get CultureInfo which was configured at the moment application was launched and will not update if the setting have been changed afterwards. So, how to get CultureInfo currently configured in Control Panel -> Regional and Language Settings? Darin Dimitrov As @Christian proposed ClearCachedData is the method to use. But according to MSDN: The ClearCachedData method does not refresh the information in the Thread.CurrentCulture property for existing threads

Is Int32.ToString() culture-specific?

只谈情不闲聊 提交于 2019-11-27 04:43:58
I'm running a beta version of ReSharper, and it's giving me warnings for the following code: int id; // ... DoSomethingWith(id.ToString()); The warning is on the id.ToString() call, and it's telling me "Specify a culture in string conversion explicitly". I understand the warning, and I know how to fix it -- just change the code to the much more unwieldy id.ToString(CultureInfo.InvariantCulture) . But my question is: is that necessary? I mean, obviously it's important to specify the culture when you're using types like DateTime (different cultures have different date formats) and Double

String.Format not converting integers correctly in arabic

丶灬走出姿态 提交于 2019-11-27 04:34:29
问题 I have a problem with String.Format. The following code formats the string correctly apart from the first integer. Current culture is set to Iraqi arabic (ar-IQ): int currentItem= 1; string of= "من"; int count = 2; string formatted = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", currentItem, of, count); The text is formatted right to left and the 2 is converted to an arabic digit, but the 1 isn't. Any ideas? 回答1: The default behaviour for converting numeric values is "Context", which

Culture sensitive ParseFloat Function in JavaScript?

↘锁芯ラ 提交于 2019-11-27 02:48:05
问题 Do anyone have suggestion for writing culture sensitive ParseFloat Function in JavaScript, So that when I have a string 100,000.22 in US culture format the parse float function returns 100000.22 whereas if I enter 100.000,22 in Swedish Culture it returns 100000.22 in float? 回答1: I've improved mwilcox' function to handle values withous separators. function parseFloatOpts (str) { if(typeof str === "number"){ return str; } var ar = str.split(/\.|,/); var value = ''; for (var i in ar) { if (i>0 &

How can I display culture-specific native digits instead of Arabic numerals?

穿精又带淫゛_ 提交于 2019-11-27 02:08:26
问题 I want to convert a numeric value to a string, displaying culture-specific digits. For example, the Dari language used in Afghanistan (culture name "prs-AF") uses Eastern-Arabic numerals instead of the Arabic numerals used in most Western cultures ( 0,1,2,3,4,5,6,7,8,9 ). When examining the CultureInfo class built into the Framework, it lists the correct native digits (screenshot taken from output in LinqPad): CultureInfo.CreateSpecificCulture("prs-AF").NumberFormat.NativeDigits However, when

Culture invariant Decimal.TryParse()

北城以北 提交于 2019-11-27 02:03:34
问题 I'm writing a custom string to decimal validator that needs to use Decimal.TryParse that ignores culture (i.e. doesn't care if the input contains "." or "," as decimal point separator). This is the suggested method: public static bool TryParse( string s, NumberStyles style, IFormatProvider provider, out decimal result ) I can't figure out what to use as the 3rd parameter. The examples I've seen look like this: culture = CultureInfo.CreateSpecificCulture("en-GB"); Decimal.TryParse(value, style

How can i convert english digits to arabic digits?

て烟熏妆下的殇ゞ 提交于 2019-11-27 01:59:46
I have this C# code for example DateTime.Now.ToString("MMMM dd, yyyy"); Now the current thread is loading the Arabic culture. So the result is like this ???? 19, 2010 But i don't want the '2010' and the '19' to be in English (also known as Latin or West Arabic digits) - I want East Arabic numbers like "٢". I tried DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.GetCultureInfo("ar-lb")); gave the same result. So any idea? Marcel B Thy this workaround (just list all cultures you want to use this numerals in the string array): private static class ArabicNumeralHelper { public static string

Get the currency from current culture?

放肆的年华 提交于 2019-11-27 01:44:01
问题 Is there a way to get current information dynamically from the apps culture settings? Basically if the user has set the culture to US I want to know the currency is dollars, or if they have it set to UK I want to pound sterling etc... etc.. This is so I can send this information to PayPal when a payment is being made 回答1: Use the RegionInfo.ISOCurrencySymbol property. For example: var ri = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID); Console.WriteLine(ri