Tag: culture

C#/ .NET内置转换例程的长度单位?

C#/ .NET库是否内置例程或常量,用于将毫米转换为英寸? 如果是这样,我在哪里可以找到它们? (我只是不想一次又一次地生成重复的代码。)

CultureInfo(来自同一文化)的实例基于OS的变化

我有一个写下这样日期的网站: CultureInfo cultureInfo = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => string.Equals(c.TwoLetterISOLanguageName, MvcApplication.Language)); return string.Concat(date.Day, “.”, cultureInfo.DateTimeFormat.GetAbbreviatedMonthName(date.Month)); 在我的PC(Windows 7,Service Pack 1,西class牙文化)和服务器(Windows Server 2012,英语文化)中, MvcApplication.Language就是这样,我从列表中得到的文化是: es-ES 。 我希望他们都写相同的字符串(他们有不同的文化,但我没有使用CurrentCulture )。 然而,我的PC和Abr.的结果非常好Abr. 在服务器中。 我已经尝试使用LinqPAD从MvcApplication.Language隔离出来,但它仍然不同。 我打印了AbbreviatedDayNames和AbbreviatedMonthNames的数组,它们在每台计算机上都不同。 我做错了什么或这是预期的行为? 如何使其完全独立于Windows /用户文化?

为什么英语(加勒比海)的文化名称为“en-029”?

为什么英语(加勒比海)的文化名称为“en-029”? 我知道“en-CA”用于英语(加拿大),但为什么029? 它意味着什么? 为什么选择它?

货币文化格式不适用于DataGridView列

我有2个DataGridViews(DGV),并且我都有我要格式化的货币列。 我写的代码似乎在一个中工作,但在另一个中则不起作用。 两个DGV都以这种方式设置:数据首先加载到DataTable中。 然后BindingSource链接到此DataTable。 最后,DGV将这个BindingSource对象用于他们的数据。 我在表单的Load事件中使用以下代码来自定义两个DGV的货币列: dataGridView.Columns[columnIndexHere].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo(“de-DE”); dataGridView.Columns[columnIndexHere].DefaultCellStyle.Format = String.Format(“c”) 似乎将一个DGV中的列格式化为另一个DGV。 此外,它的NOT工作的DGV在其父窗体中甚至没有那么多的function代码..我检查了代码和DGV的属性,看看我是否在其他地方更改格式,但是我什么都没发现.. 两个DGV加载数据的方式之间的唯一微小区别是,对于第一个DGV的DataTable(其中格式化工作),数据通过SELECT语句(通过我自己的函数)加载…在第二个DGV的DataTable(用于哪个格式化不起作用),我不从DB加载任何数据,而只是手动定义列(在DataTable中),因为在这种情况下用户需要输入数据.. 任何线索为什么格式化不能在第二个DGV上工作? 编辑:添加更多信息: 为了演示这个问题,我创建了一个新的C#winforms项目,在其上只添加了一个DataGridView,并将以下代码添加到Load事件中。 即使对于此代码,也没有进行货币格式化: DataTable dataTable = new DataTable(); dataTable.Columns.Add(“ColA”); dataTable.Columns.Add(“ColB”); dataTable.Columns.Add(“ColC”); dataTable.Rows.Add(“John”, 832.293, “London”); dataTable.Rows.Add(“Alice”, 32972978.20489, “Atlanta”); dataTable.Rows.Add(“Mark”, 9184793284739, “Tokyo”); BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = dataTable; dataGridView1.DataSource = bindingSource; var format = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); format.CurrencySymbol = “Mn. “; […]

非美国文化中具有DateTime的String.FormatException

我得到一个String.FormatException试图转换/解析一个字符串当文化不是非美国。 奇怪的是,字符串是通过应用与用于将其解析回字符串的格式和文化完全相同的格式和文化生成的。 在下面的代码中,所有这些版本都将失败: const string culture =“ja-JP”; const string format =“dd MMM yyyy”; //包括{0:}的原始post中的错误 CultureInfo info = new CultureInfo(culture); Thread.CurrentThread.CurrentCulture = info; Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culture); // string toParse = String.Format(info,format,DateTime.Now); //原帖中的错误 string toParse = DateTime.Now.ToString(format); System.Diagnostics.Debug.WriteLine(string.Format(“Culture format = {0},Date = {1}”,culture,toParse)); 尝试 { DateTime输出= DateTime.ParseExact(toParse,format,CultureInfo.InvariantCulture); // DateTime output = DateTime.ParseExact(toParse,format,info); // DateTime output = DateTime.ParseExact(toParse,format,info,DateTimeStyles.None); […]

CultureInfo.CurrentCulture在String.Format()中是否真的必要?

您如何认为在方法String.Format(string, object)提供IFormatProvider真的很有必要? 写完整变体是否更好 String.Format(CultureInfo.CurrentCulture, “String is {0}”, str); 要不就 String.Format(“String is {0}”, str); ?

在编译时禁用Dll文化文件夹

我正在使用2 dll( Microsoft.Expression.Interactions.dll和System.Windows.Interactivity.dll ),当编译父应用程序时,创建文化文件夹的负载: 每个内部都是2个dll( Microsoft.Expression.Interactions.resources.dll和System.Windows.Interactivity.resources.dll )。 我已经google了,我找不到任何有关如何阻止这个烦人的自动生成内容的事情。

.NET如何比较两个表示文件名的字符串,正确地忽略大小写

鉴于(至少在NTFS上)Windows上的文件系统不区分大小写,我想将String fileA与String fileB进行比较: fileA.Equals(fileB, StringComparison.CurrentCultureIgnoreCase) 那么问题就变成我应该使用哪种文化,默认的当前(ui?)文化是否足够? 我似乎无法为此目的找到任何BCL方法。

为国家,语言组合创建自定义CultureInfo

我正在开发一个.net 4.5应用程序,需要多语言支持多文化等。 以下是国家/语言的示例列表 俄罗斯/俄罗斯 比利时/法国 比利时/荷兰 对于上述所有内容,可以根据上述文化名称创建CultureInfo对象 RU-RU FR-BE NL-BE 当用户进入站点时,我将Thread.CurrentThread.CurrentCulture和Thread.CurrentThread.CurrentUICulture设置为使用上述名称创建的文化,例如。 Thread.CurrentThread.CurrentCulture = new CultureInfo(“nl-BE”, false) Thread.CurrentThread.CurrentUICulture = new CultureInfo(“nl-BE”, false) 以上所有名称均为有效的文化名称。 不,但我需要在俄罗斯添加另一种文化名称,英语。 但问题是代码en-RU无效,所以当我创建new CultureInfo(“en-RU”, false)我得到一个CultureNotFoundException,因为en-RU无效。 有了这种文化,我希望俄罗斯的格式等数字,日期等,但我希望网站上的语言是英语。 是否可以使用国家/地区(俄罗斯)的行为为无效的文化名称创建自定义CultureInfo对象?

使用当前文化定义的12或24小时格式从DateTime获取一天中的小时

.Net具有内置的DateTime ToShortTimeString()函数,该函数使用CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern格式。 它会为en-US返回类似的内容:“下午5:00”。 对于像de-DE这样的24小​​时文化,它将返回“17:00”。 我想要的是一种方法,只返回适合每种文化的小时(上面的情况中的“下午5点”和“17”)。 什么是最好/最干净的方法? 谢谢!