问题描述
我如何本地化比今天以外的DAYOFWEEK结果
以下的作品就好了当天的:
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??
编辑:我想出了一个可能的(也可能是非常非常错误的)的解决方案可能是整整一个星期创建的DateTime
的值,然后使用与Date.toString(DDDD,新的CultureInfo(IT-IT));
在他们身上,但是这似乎只是错误这么多层次
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.
推荐答案
如何
DateTimeFormatInfo.CurrentInfo.GetDayName( dayOfWeek )
或
DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName( dayOfWeek )
只是需要DAYOFWEEK枚举,并返回字符串,它是当前文化名
Simply takes a DayOfWeek enumeration and returns string that is the name in the current culture.
编辑:
如果你正在寻找特定文化这将是
If you're looking for a specific culture it would be
var cultureInfo = new CultureInfo( "it-IT" );
var dateTimeInfo = cultureInfo.DateTimeFormat;
然后你可以打电话GetDayName或GetAbbreviatedDayName任您选择。
then you can call GetDayName or GetAbbreviatedDayName as you choose.
这篇关于C#文化:本地化星期几?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!