The code sample is a ASP.NET page's code behind file that tries to output the week of the year, given the date.
For example, if the input date is Jan 1,2008, then it's the first week of the year. In the code below, the getWeek() function is responsible for returning the week's number.
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
public partial class WeekCalc : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write(getWeek()); } public int getWeek() {
DateTime date = DateTime.Now; System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("no"); System.Globalization.Calendar cal = cult_info.Calendar; int weekNo = cal.GetWeekOfYear(date, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek); return weekNo; }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|