cultureinfo

C# DateTime conversion same culture on different machines

妖精的绣舞 提交于 2019-12-11 04:18:24
问题 If i run this console app from my test italian machine: static void Main(string[] args) { String date = DateTime.Now.ToString("yyyy-MM-dd HH:mm", new CultureInfo("it-IT")); Console.WriteLine(date); Console.ReadKey(); CultureInfo ci = new CultureInfo("it-IT"); Console.WriteLine("Time: " + ci.Name + " " + ci.DateTimeFormat.TimeSeparator); Console.WriteLine("Date: " + ci.Name + " " + ci.DateTimeFormat.DateSeparator); Console.ReadKey(); } displays: 2013-07-25 15:40 Time: it-IT : Date: it-It / but

CultureInfo.InvariantCulture in plain english

老子叫甜甜 提交于 2019-12-11 03:13:45
问题 I know that culture rules for dates/numbers is enough for an entire book, I think I have a simple question though.. Does using InvariantCulture basically mean that you explicitly define what culture the value (date/number/whatever) will be inputted/displayed as? And it overrides any other culture setting (such as the user agent's setting)? If an app is built for an audience of one and only one culture, would it make sense to use InvariantCulture and define how you want values inputted

How to set the culture info in unmanaged C++?

◇◆丶佛笑我妖孽 提交于 2019-12-11 02:24:27
问题 I got a program written in unmanaged C++, I need to get the cultural info from the system and set that info to the current execution thread in my c++ application. Thanks. 回答1: In unmanaged C++ on windows, what you need is the Locale. Culture is a term defined in .NET, as a replacement for that term. There's a whole host of functions, but the one where you need to start is called SetThreadLocale. SetThreadLocale Function (Windows) @ MSDN Within the documentation at MSDN, it appears that there

C# CultureInfo.GetCultures returns a (nearly) empty list

谁说胖子不能爱 提交于 2019-12-10 21:26:24
问题 Windows 8.1 Pro, Visual Studio 2013, .NET Framework 4.5.2 Here is the code: var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); Console.WriteLine("Culture count: " + cultures.Length); Here is the output: Culture count: 2 The two cultures are zh-CHS and zh-CHT which are added in the CultureData.GetCultures method. The other cultures are supposed to be returned by CultureData.nativeEnumCultureNames but it appears that this is returning an empty array. This behavior appears to be

How to display dynamic culture formatted number in a WPF UserControl

左心房为你撑大大i 提交于 2019-12-10 17:57:54
问题 I would like to dynamically set the culture format of the Number textblock with culture and number values passed through to MyUserControl. The MyCulture and Number values are passed to MyCustomControl and will be of the form "en-GB", "en-US" etc. I did something similar in asp.NET MVC with an extension method but need help for how to piece this together in WPF. Example MVC Extension Method public static MvcHtmlString CulturedAmount(this decimal value, string format, string locale) { if

Problem creating correct path concatenating left to right with right to left sections

浪尽此生 提交于 2019-12-10 16:16:30
问题 I have simplified in a big way the problem and here is the sample code: string outputString = string.Empty; string joinOutputString = string.Empty; string pathOutputString = string.Empty; string[] myStrings = new string[4]; myStrings[0] = "First entry"; myStrings[1] = "اول"; myStrings[2] = "دوم"; myStrings[3] = "Last entry"; StringBuilder sb = new StringBuilder(); for (int i = 0; i < myStrings.Length; i++) { joinOutputString = string.Join(@"\", joinOutputString, myStrings[i]); outputString =

Instances of CultureInfo (from same culture) changing based on OS

六眼飞鱼酱① 提交于 2019-12-10 15:29:10
问题 I've a web site which writes a date like this: CultureInfo cultureInfo = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => string.Equals(c.TwoLetterISOLanguageName, MvcApplication.Language)); return string.Concat(date.Day, ".", cultureInfo.DateTimeFormat.GetAbbreviatedMonthName(date.Month)); In both my PC (Windows 7, Service Pack 1, Spanish culture) and the server (Windows Server 2012, English Culture) the MvcApplication.Language is es so the culture I get from the list is

How to use CultureInfo to format deprecated currencies?

一世执手 提交于 2019-12-10 15:09:19
问题 In dotnet, the recommended way of formatting currencies in a culture-specific way, is (as far as I can find): using System.Globalization var info = CultureInfo.GetCultureInfo("en-GB") return string.Format(info, "{0:c}", 1234.5678) This returns: £1,234.57 However. No specific currency is given here. So if Great Britain ever converts to Euro, the same method would suddenly return something like: € 1,234.57 This has just happened to Latvia. This year, it converted to the euro. Various systems

Can i create a new CultureInfo from a two-character language code?

怎甘沉沦 提交于 2019-12-10 14:23:47
问题 I need to format a number, based on a culture, but all I have is the Accept-Language from the HTTP request, which is a two-letter code like fr (for French) Is this enough to create a CultureInfo that can handle numbers? 回答1: Yes you can. The following code: var ci = new CultureInfo("fr"); Console.WriteLine(13.45.ToString(ci)); outputs "13,45" which is using the french decimal separator in the number. The CultureInfo documentation says: A neutral culture is specified by only the two-letter

Change datetime format from one to another programmatically

旧街凉风 提交于 2019-12-10 11:47:39
问题 In my program, I need to change the input datetime information from Turkish (d.M.yyyy) language to English (M/dd/yyyy). When client edits datetime information in Turkish datetime format(For Example: 24.9.2015), i need to convert this information in English datetime format(Like; 9/24/2015). I'm trying to parse the input, but not convert the correct format that i need, code block as in the following. DateTime.TryParseExact(InputDate,"d.M.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None,