C#:设置初始DAYOFWEEK周一周日不 [英] C#: Set initial DayOfWeek as Monday not Sunday

查看:2288
本文介绍了C#:设置初始DAYOFWEEK周一周日不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来设置第一DAYOFWEEK为星期一= 0不是星期天?



 (INT)dateList [0] .DayOfWeek == 0)// 0 =星期日


解决方案

您将需要创建一个自定义的文化,并指定初始DAYOFWEEK周一。您的自定义文化的一个实例,将需要设置为任何情况下,通常是用来访问区域性信息(即 Thread.CurrentCulture )。下面的文章应该让你开始创建一个自定义的文化:



如何:创建自定义的文化



编辑:



我只是重读你的问题,我注意到的东西。你不能改变的DAYOFWEEK财产......这仅仅是一个枚举值。您将需要的星期几比作请将CultureInfo.DateTimeFormat属性的Firstdayofweek可属性:

  dateList [0] == .DayOfWeek Thread.CurrentCulture.DateTimeFormat.FirstDayOfWeek 

默认情况下, Firstdayofweek可周日。如果您创建一个自定义的文化,也可能是一周的任何一天你选择(即周一)。


Is there a way to set the first DayOfWeek as Monday = 0 not Sunday?

(int)dateList[0].DayOfWeek == 0) // 0 = Sunday

解决方案

You would need to create a custom culture, and specify the initial DayOfWeek as Monday. An instance of your custom culture would need to be set to whatever context is normally used to access culture information (i.e. Thread.CurrentCulture). The following article should get you started on creating a custom culture:

How to: Create Custom Cultures

EDIT:

I just reread your question, and I noticed something. You can not change the DayOfWeek property...that is simply an enumeration value. You would need to compare the DayOfWeek to the FirstDayOfWeek property of the CultureInfo.DateTimeFormat property:

dateList[0].DayOfWeek == Thread.CurrentCulture.DateTimeFormat.FirstDayOfWeek

By default, FirstDayOfWeek is Sunday. If you created a custom culture, it could be any day of the week you so choose (i.e. Monday).

这篇关于C#:设置初始DAYOFWEEK周一周日不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆