.Net时间计算函数,统计某一天是一年的第几周,这一周从哪天开始到哪天结束
/// <summary> /// 计算某年第一周的天数
/// </summary>
/// <param name="dt">某年中的一个时间</param>
/// <returns></returns>
public static int DaysInFirstweekInYear(DateTime dt)
{
DateTime FirstDate = Convert.ToDateTime(string.Format("{0}-1-1", dt.Year));
int DayOfWeekInYear = DayOfWeek(FirstDate);
int DaysInFirstWeek = 8 - DayOfWeekInYear;
return DaysInFirstWeek;
}
/// <summary>
/// 一年中的第几周
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static int WeekOfYear(DateTime dt)
{
int days = DaysInFirstweekInYear(dt);
int dayofyear = dt.DayOfYear;
if (dayofyear < days) return 1;
else
{
int week2 = (int)Math.Ceiling((double)(dayofyear - days) / (double)7);
return week2 + 1;
}
}
/// <summary>
/// 传入某一天,输出这一周的起始日期
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static DateTime[] DatesIncludeDay(DateTime dt)
{
DateTime[] dts = new DateTime[2];
int dayofweek = DayOfWeek(dt);
dts[0] = dt.AddDays(1 - dayofweek);
dts[1] = dt.AddDays(7 - dayofweek);
return dts;
}
/// <summary>
/// 计算星期几,转换为数字
/// </summary>
/// <param name="dt">某天的日期</param>
/// <returns></returns>
public static int DayOfWeek(DateTime dt)
{
string strDayOfWeek = dt.DayOfWeek.ToString().ToLower();
int intDayOfWeek = 0;
switch (strDayOfWeek)
{
case "monday":
intDayOfWeek = 1;
break;
case "tuesday":
intDayOfWeek = 2;
break;
case "wednesday":
intDayOfWeek = 3;
break;
case "thursday":
intDayOfWeek = 4;
break;
case "friday":
intDayOfWeek = 5;
break;
case "saturday":
intDayOfWeek = 6;
break;
case "sunday":
intDayOfWeek = 7;
break;
}
return intDayOfWeek;
}
调用:
DateTime dt = Convert.ToDateTime("2013-1-6");
Dictionary<string, DateTime> dict = new Dictionary<string, DateTime>();
dict.Add("0001", DateTime.Now.AddDays(-100));
dict.Add("0002", DateTime.Now.AddDays(-99));
dict.Add("0003", DateTime.Now.AddDays(-98));
dict.Add("0004", DateTime.Now.AddDays(-97));
dict.Add("0005", DateTime.Now.AddDays(-96));
dict.Add("0006", DateTime.Now.AddDays(-95));
dict.Add("0007", DateTime.Now.AddDays(-94));
dict.Add("0008", DateTime.Now.AddDays(-93));
dict.Add("0009", DateTime.Now.AddDays(-92));
dict.Add("0010", DateTime.Now.AddDays(-91));
dict.Add("0011", DateTime.Now.AddDays(-90));
dict.Add("0012", DateTime.Now.AddDays(-89));
dict.Add("0013", DateTime.Now.AddDays(-88));
dict.Add("0014", DateTime.Now.AddDays(-87));
dict.Add("0015", DateTime.Now.AddDays(-86));
dict.Add("0016", DateTime.Now.AddDays(-85));
dict.Add("0017", DateTime.Now.AddDays(0));
dict.Add("0018", DateTime.Now.AddDays(1));
dict.Add("0019", DateTime.Now.AddDays(2));
string str = "";
foreach(KeyValuePair<string,DateTime> kv in dict)
{
Dat
补充:Web开发 , ASP.Net ,
- 更多asp疑问解答:
- asp正则过滤重复字符串的代码
- 用asp过滤全部html但保留br类似的符号
- 会asp,但感觉asp要过点,想学php。但我一般做的都是小公司的站,用access数
- PHP的空间可以用ASP的源代码吗?
- 以前做asp程序,现在应该怎样发展?是学.net还是php
- 以前做asp程序,现在应该怎样发展?是学.net还是php
- 想做一个市级的人才网acess,sql数据库,语言asp,jsp,php分别用哪种好
- jsp,asp,php 区别
- 我想找一个有比较多漏洞的网站的源码,比如可以asp,php注入等都可以。供学习研究用。请提供下载地址。。
- 现在候找人做个网站,用ASP,还是PHP语言去做好
- asp,php ,jsp,.net 对于做网站前台的重要吗?
- asp和php的区别是什么?
- 我是新手SEO菜鸟 请问wp dw php asp cms myspl dede 这些软件应该如何区分呀?
- 网页制作相关的三种语言:ASP JSP PHP那个好点,简单点?
- 网页制作相关的三种语言:ASP JSP PHP那个好点,简单点?