10. januar 2006 - 10:05
#3
mit standard eksempel:
using System;
using System.Globalization;
using Microsoft.VisualBasic;
namespace E
{
public class TimeUtil
{
public static int Week1(int year, int mon, int day)
{
return (new CultureInfo("da-DK", false)).Calendar.GetWeekOfYear(new DateTime(year, mon, day), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}
public static int Week2(int year, int mon, int day)
{
return DateAndTime.DatePart("ww", new DateTime(year, mon, day), Constants.vbMonday, Constants.vbFirstFourDays);
}
public static int Week3(int year, int mon, int day)
{
int a = (14 - mon) / 12;
int y = year + 4800 - a;
int m = mon + 12*a - 3;
int JD = day + (153 * m + 2)/5 + 365*y + y/4 - y/100 + y/400 - 32045;
int d4 = (((JD + 31741 - JD % 7) % 146097) % 36524) % 1461;
int L = d4 / 1460;
int d1 = ((d4 - L) % 365) + L;
return d1 / 7 + 1;
}
}
public class TestClass
{
public static void Test(int year, int mon, int day)
{
Console.WriteLine((new DateTime(year, mon, day)).ToString("dddd dd/MM/yyyy") + ": " +
TimeUtil.Week1(year, mon, day) + " " +
TimeUtil.Week2(year, mon, day) + " " +
TimeUtil.Week3(year, mon, day));
}
public static void Main(string[] args)
{
for(int y = 2002; y < 2006; y++)
{
Test(y, 12, 28);
Test(y, 12, 29);
Test(y, 12, 30);
Test(y, 12, 31);
Test(y+1, 1, 1);
Test(y+1, 1, 2);
Test(y+1, 1, 3);
Test(y+1, 1, 4);
Test(y+1, 1, 5);
Test(y+1, 1, 6);
}
}
}
}
10. januar 2006 - 13:25
#12
det vil alt så sige at jeg skal bruge den her
public static int Week3(int year, int mon, int day)
{
int a = (14 - mon) / 12;
int y = year + 4800 - a;
int m = mon + 12*a - 3;
int JD = day + (153 * m + 2)/5 + 365*y + y/4 - y/100 + y/400 - 32045;
int d4 = (((JD + 31741 - JD % 7) % 146097) % 36524) % 1461;
int L = d4 / 1460;
int d1 = ((d4 - L) % 365) + L;
return d1 / 7 + 1;
}
Men hvorfor skal jeg dog havde har 3 arg. med over??