如何使用西班牙月份和星期几的名称在 MAUI 中格式化日期?

huangapple go评论62阅读模式
英文:

How can the date be formatted using Spanish month names and day names in MAUI

问题

在使用.NET Framework进行开发时,我只需在应用程序(Winforms或Web)的开头设置CurrentUICulture为"es-CL"等文化。这样,整个应用程序中的日期格式都会更改为"es-CL"(月份和日期名称为西班牙语,小数分隔符为",",千位分隔符为"。")。那真是太棒了。

我如何在MAUI中实现相同的效果?我不关心创建多语言应用程序,所以是否有一种简单的方法可以做到这一点?我不想为仅一个语言创建一个resx文件。

谢谢
Jaime

英文:

When I used to develop using .NET Framework, I just set the CurrentUICulture at the beginning of the application (Winforms or Web) to a culture such as "es-CL". With that, all date formatting accross the whole application changes to "es-CL" (month and day names in Spanish, decimal separator as the "," and thousand separator as the "."). That was extraordinary.

How can I achieve the same in MAUI? I don't care about creating a multi language application, so, is there an easy way to do this? I don't want to create a resx file for just one language.

Thanks
Jaime

答案1

得分: 1

CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("es-CL");

在MauiProgram.cs文件中使用时有效。

英文:

@ToolmakerSteve thanks. It worked when I use

CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("es-CL");

in MauiProgram.cs file.

huangapple
  • 本文由 发表于 2023年6月8日 07:08:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427621.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定