判断一个时间为当时年份的第几周、第几季度?

gang2yan 2010-08-19 05:02:59
判断一个时间为当时年份的第几周、第几季度?

例如: 2008-08-08 是当年的第几周、第几季度?
...全文
396 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
村长_乐 2010-08-19
  • 打赏
  • 举报
回复
http://blog.sina.com.cn/letisgole
这里面很详细...多看看对你以后时间的处理有帮助...
龍月 2010-08-19
  • 打赏
  • 举报
回复
顶了
学习了
q107770540 2010-08-19
  • 打赏
  • 举报
回复


private int DatePart(System.DateTime dt)
{
int weeknow = Convert.ToInt32(dt.DayOfWeek);//今天星期几
int daydiff = (-1) * (weeknow + 1);//今日与上周末的天数差
int days = System.DateTime.Now.AddDays(daydiff).DayOfYear;//上周末是本年第几天
int weeks = days / 7;
if (days % 7 != 0)
{
weeks++;
}
//此时,weeks为上周是本年的第几周
return (weeks + 1);
}


DateTime dt = Convert.ToDateTime("2010-08-19");

Response.Write(DatePart(dt).ToString()); //结果:34




DateTime dt = Convert.ToDateTime("2008-08-08 ");
int i = dt.Month;
double d= (double)i / 2;
if (d < 2.0)
{
Response.Write("第1季度");
}
else if (d >= 2 && d <= 3)
{
Response.Write("第2季度");
}
else if (3 < d &&d< 5)
{
Response.Write("第3季度");
}
else
{
Response.Write("第4季度");
}

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧