开发者

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

开发者 https://www.devze.com 2023-04-01 15:33 出处:网络
I have a code in vb开发者_JS百科 var weekOfYear=DateAndTime.DatePart(DateInterval.WeekOfYear, date, FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFullWeek);

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

精彩评论

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