将报告中的日期更改为西班牙语
Change date in the report to language Spanish
我在服务器上发布了 C# asp net MVC 应用程序,该服务器使用西班牙语,但在报告(Crystal 报告)中以英语显示日期..
如何用西班牙语显示它?
上面的日期是"Date of the data (crystal report)"并且
下面另外两个日期是你进入申请
PD:重要的是要用西班牙语提及我的电脑,所以当我将我的电脑换成英语时,用西班牙语提及日期。
你应该使用classCultureInfo
, which enables you to specify any language and styles for a language and/or a country. You can read about the .NET supported cultures here。在这种情况下,您只需将日期转换为带有 ToString()
版本的字符串,该版本将 CultureInfo
作为参数。您可以在您的代码中创建这种文化,或访问默认文化(默认是您计算机的语言,但在 ASP.NET 中,您可以为每个用户保留一种特殊的文化)。这是一个例子:
using System.Globalization;
// ...
yourDate.ToString(new CultureInfo("es-ES")); // Convert the date to a normal date string with Spain's Spanish culture
您可以为 Spain
(或您喜欢的任何国家/地区)硬编码 CultureInfo
,然后将其传递给 DateTime
对象的 ToString()
方法。请注意,我还使用它来获取该文化的 "LongDatePattern",但如果需要,您可以指定自己的自定义模式。:
var date = new DateTime(2019, 1, 28);
var englishUSCulture = new CultureInfo("en-US");
var spanishSpainCulture = new CultureInfo("es-ES");
Console.WriteLine("English-US long date ".PadRight(27, '.') + " " +
date.ToString(englishUSCulture.DateTimeFormat.LongDatePattern),
englishUSCulture);
Console.WriteLine("Spanish-Spain long date ".PadRight(27, '.') + " " +
date.ToString(spanishSpainCulture.DateTimeFormat.LongDatePattern,
spanishSpainCulture));
输出
我在服务器上发布了 C# asp net MVC 应用程序,该服务器使用西班牙语,但在报告(Crystal 报告)中以英语显示日期..
如何用西班牙语显示它?
上面的日期是"Date of the data (crystal report)"并且 下面另外两个日期是你进入申请
PD:重要的是要用西班牙语提及我的电脑,所以当我将我的电脑换成英语时,用西班牙语提及日期。
你应该使用classCultureInfo
, which enables you to specify any language and styles for a language and/or a country. You can read about the .NET supported cultures here。在这种情况下,您只需将日期转换为带有 ToString()
版本的字符串,该版本将 CultureInfo
作为参数。您可以在您的代码中创建这种文化,或访问默认文化(默认是您计算机的语言,但在 ASP.NET 中,您可以为每个用户保留一种特殊的文化)。这是一个例子:
using System.Globalization;
// ...
yourDate.ToString(new CultureInfo("es-ES")); // Convert the date to a normal date string with Spain's Spanish culture
您可以为 Spain
(或您喜欢的任何国家/地区)硬编码 CultureInfo
,然后将其传递给 DateTime
对象的 ToString()
方法。请注意,我还使用它来获取该文化的 "LongDatePattern",但如果需要,您可以指定自己的自定义模式。:
var date = new DateTime(2019, 1, 28);
var englishUSCulture = new CultureInfo("en-US");
var spanishSpainCulture = new CultureInfo("es-ES");
Console.WriteLine("English-US long date ".PadRight(27, '.') + " " +
date.ToString(englishUSCulture.DateTimeFormat.LongDatePattern),
englishUSCulture);
Console.WriteLine("Spanish-Spain long date ".PadRight(27, '.') + " " +
date.ToString(spanishSpainCulture.DateTimeFormat.LongDatePattern,
spanishSpainCulture));
输出