C# 文化:本地化 DayOfWeek?
如何本地化除今天以外的 DayOfWeek?
以下内容对于当天来说效果很好:
DateTime.Now.ToString("dddd", new CultureInfo("it-IT"));
但是我如何本地化一周中的所有日子?
编辑:我想出的一个可能的(可能非常非常错误)的解决方案可能是创建一整周的 DateTime 值,然后使用 date.ToString("dddd", new CultureInfo("it-IT")); 对他们来说,但这在很多层面上似乎都是错误的。
How do I localize a DayOfWeek other than today?
The following works just fine for the current day:
DateTime.Now.ToString("dddd", new CultureInfo("it-IT"));
But how can I localize all days of the week??
Edit: A possible (and probably very, very wrong) solution I came up with could be to create DateTime
values for an entire week, and then use date.ToString("dddd", new CultureInfo("it-IT"));
on them, but that just seems wrong on so many levels.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了 MerickOWA 的答案之外,我们现在可以创建扩展方法:
In addition to MerickOWA's answer, we can now create extension methods:
怎么样
或
简单地采用 DayOfWeek 枚举并返回当前区域性中的名称字符串。
编辑:
如果您正在寻找特定的文化,那么
您可以根据您的选择调用 GetDayName 或 GetAbbreviatedDayName。
如果您想要全部,甚至还有 AbbreviatedDayNames/DayNames 数组
How about
or
Simply takes a DayOfWeek enumeration and returns string that is the name in the current culture.
Edit:
If you're looking for a specific culture it would be
then you can call GetDayName or GetAbbreviatedDayName as you choose.
There's even a AbbreviatedDayNames/DayNames arrays if you want them all