开发者

Equiv to get week of year by datepart in c#?

I have a code in vb开发者_JS百科

var weekOfYear=DateAndTime.DatePart(DateInterval.WeekOfYear, date, FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFullWeek);

which is http://msdn.microsoft.com/en-us/library/ms127415.aspx .

I caną find nothing equivalent to this in c¤, but I don't want to create new algorithm, which I think would have some bugs :)

Which method should I use?


public static int GetWeekNumber(DateTime dtPassed)
{
        CultureInfo ciCurr = CultureInfo.CurrentCulture;
        int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
        return weekNum;
}

this can help


You can always include the Microsoft.VisualBasic assembly in your C# project and use the same methods you were using in VB.NET.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜