cultureinfo

CultureInfo & DateTimeInfo: How to check if is 24 hour time?

余生长醉 提交于 2019-11-29 03:55:42
I'm modifying a globalized web application which uses stored CultureInfo for each logged in user. The client would like time data entry to be localized. Displaying is not a problem as the formatting is already available. However I need to detect if the current cultureinfo is for 24 hour time or am/pm so I can display the correct input boxes (not just a textfield). My initial idea was to check the DateTimeInfo property of CultureInfo and see if the ShortTimePattern contained a capital H or a lower case h but this didn't feel robust enough for me. Is there a better way? I've read the class

How to convert “12,4” to decimal en-Us culture

元气小坏坏 提交于 2019-11-29 02:11:50
I have a decimal value ("133,3") stored in string column in the database, in norway culture. after that user changed the regional setting to english-Us. when I convert "133,3" to decimal using CultureInfo.InvariantCulture, getting invalid value or error. is there any best way to handle this scenario in C# application? regards, Anand Regardless of the system culture, if you specify CultureInfo.InvariantCulture you won't be able to parse "133,3" as a decimal to 133.3. The same is true for US English. You could just specify a Norwegian culture when parsing the value (using the overload of decimal

datetime.tostring month and day language

半城伤御伤魂 提交于 2019-11-28 23:24:12
i have a list of email addresses of people that have different nationalities (for each person i have the iso code) when i send the email to all these people, in the text of the mail i need to to convert a datetime field to a string formatted in their specific culture. for this i'm doing CultureInfo ci = new CultureInfo(ISO); myStringDate = myDate.ToString(ci.DateTimeFormat.ShortDatePattern); and work perfect, but if i use LongDatePattern instead short, for displaying date like "Monday, 13 June 2010" its work fine except the language of the day and month. if the person culture is it-IT i need

DateTime.Now.DayOfWeek.ToString() with CultureInfo

荒凉一梦 提交于 2019-11-28 20:59:52
I have the code: DateTime.Now.DayOfWeek.ToString() That give's me the english day of the week name, I want to have the german version, how to add CultureInfo here to get the german day of the week name? var culture = new System.Globalization.CultureInfo("de-DE"); var day = culture.DateTimeFormat.GetDayName(DateTime.Today.DayOfWeek); You can use the DateTimeFormat.DayNames property of the german CultureInfo . For example: CultureInfo german = new CultureInfo("de-DE"); string sunday = german.DateTimeFormat.DayNames[(int)DayOfWeek.Sunday]; Despota This is the solution in Visual Basic Dim

Could string comparisons really differ based on culture when the string is guaranteed not to change?

心已入冬 提交于 2019-11-28 18:32:14
I'm reading encrypted credentials/connection strings from a config file. Resharper tells me, "String.IndexOf(string) is culture-specific here" on this line: if (line.Contains("host=")) { _host = line.Substring(line.IndexOf( "host=") + "host=".Length, line.Length - "host=".Length); ...and so wants to change it to: if (line.Contains("host=")) { _host = line.Substring(line.IndexOf("host=", System.StringComparison.Ordinal) + "host=".Length, line.Length - "host=".Length); The value I'm reading will always be "host=" regardless of where the app may be deployed. Is it really sensible to add this

What cultures are supported by the CultureInfo class in .NET 3.5?

帅比萌擦擦* 提交于 2019-11-28 13:21:50
I need a list of cultures that are supported by .NET 3.5, regardless of the OS used. This seems to be quite a struggle to obtain, though I am not sure why! Edit: Arghh, I was not aware that it is dependent on the OS, that would explain the lack of documentation. Any ideas on what is supported by Mac/Linux OS as well? Thanks :) Unfortunately, it is OS dependent. Check here for default language support per OS. Note, the CultureInfo documentation warns: Windows versions or service packs can change the available cultures. In ASP.NET, it's the browser that's important versus the OS. It can tell you

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

£可爱£侵袭症+ 提交于 2019-11-28 11:54:33
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. "hh" is the 12-hour clock format (01 to 12). You need to use "HH" for a 24 hour clock. DateTime dt = DateTime.ParseExact(time, "HH:mm", CultureInfo.InvariantCulture); Try this: DateTime dt = DateTime

DateTimeFormat.AbbreviatedMonthNames adding a dot at the end of month's name

北战南征 提交于 2019-11-28 09:57:11
问题 Last night we migrated our web services tier from physical Windows 2008 r2 to virtual Windows 2012. We are getting tons of events on ours logs about DateTime's invalid formats, strange as we double checked our regional settings. Long story short: CultureInfo.GetCultureInfo("es-MX").DateTimeFormat.AbbreviatedMonthNames Outputs (using LinqPad5): ene. feb. mar. on our new 2012 env while on 2008 ouptus: ene feb mar Our parsing is something like this: DateTime.Parse("18 ene 16",CultureInfo

Culture sensitive ParseFloat Function in JavaScript?

試著忘記壹切 提交于 2019-11-28 09:16:40
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? Alex Polishchuk 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 && i==ar.length-1) { value += "."; } value +=ar[i]; } return Number(value); } This is a bit

Globally set String.Compare/ CompareInfo.Compare to Ordinal

空扰寡人 提交于 2019-11-28 08:24:17
问题 I'm searching for a strategy with which I can set the default sortorder of String.CompareTo to bytewise - ordinal. I need to do this without having to specify the sortorder in the call to the method. I have tried out several strategies without satisfactory results. I got as far as this: CultureAndRegionInfoBuilder crib = new CultureAndRegionInfoBuilder("foo", CultureAndRegionModifiers.Neutral); CompareInfo compareInfo = new CustomCompareInfo(); crib.Register(); In this CustomCompareInfo I try