get the week number of datetime - CSharp System

CSharp examples for System:DateTime Week

Description

get the week number of datetime

Demo Code


using System.Globalization;
using System;//from w w  w.  j  a  v  a 2s  .  co  m

public class Main{
        /// <summary>
        /// get the week number of datetime
        /// </summary>
        /// <param name="value">datetime</param>
        /// <returns>number order of week</returns>
        public static int WeekNumber(this DateTime value)
        {
            return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(value, CalendarWeekRule.FirstFourDayWeek,
                DayOfWeek.Monday);
        }
}

Related Tutorials