按工作第一天对工作日进行排序
有没有更好的方法来重新排列
DateTimeFormat.DayNames
,以便
DateTimeFormat.FirstDayOfWeek
如果
DateTimeFormat.FirstDayOfWeek = 1
dayNames 包含星期一、星期二、星期三、...
插入儿子,周一,周二,...
我目前正在使用:
CultureInfo culture = System.Globalization.CultureInfo.CurrentUICulture;
string[] DayNames = culture.DateTimeFormat.DayNames;
int FirstDayOfWeek = (int)culture.DateTimeFormat.FirstDayOfWeek;
int daysInMonth = DateTime.DaysInMonth(year, month);
string[] tempdays = new string[7];
for (int i = 0; i <= DayNames.GetUpperBound(0); i++)
{
tempdays[i] = DayNames[i == 0 ? FirstDayOfWeek :
(i == 6 - FirstDayOfWeek ? 6 :
i > 6 - FirstDayOfWeek ? 0 != (6 - (i + (FirstDayOfWeek - 1))) ?
(6 - (i + (FirstDayOfWeek - 1))) * -1 :
6 - (i + (FirstDayOfWeek - 1)) : i + FirstDayOfWeek)];
}
is there a better way of rearange the
DateTimeFormat.DayNames
acording to the
DateTimeFormat.FirstDayOfWeek
so that if
DateTimeFormat.FirstDayOfWeek = 1
dayNames containts mon,tue,wed, ...
insted of son,mon,tue, ...
I'm currently using:
CultureInfo culture = System.Globalization.CultureInfo.CurrentUICulture;
string[] DayNames = culture.DateTimeFormat.DayNames;
int FirstDayOfWeek = (int)culture.DateTimeFormat.FirstDayOfWeek;
int daysInMonth = DateTime.DaysInMonth(year, month);
string[] tempdays = new string[7];
for (int i = 0; i <= DayNames.GetUpperBound(0); i++)
{
tempdays[i] = DayNames[i == 0 ? FirstDayOfWeek :
(i == 6 - FirstDayOfWeek ? 6 :
i > 6 - FirstDayOfWeek ? 0 != (6 - (i + (FirstDayOfWeek - 1))) ?
(6 - (i + (FirstDayOfWeek - 1))) * -1 :
6 - (i + (FirstDayOfWeek - 1)) : i + FirstDayOfWeek)];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经有效地实现了模运算符,因此您可以将表达式简化为
You've effectively implemented to modulo operator, so you can simplify your expression to