首页 > 开发 > 综合 > 正文

C#时间函数扩展

2024-07-21 02:18:15
字体:
来源:转载
供稿:网友
//本周是本年第几周


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);
}


//本周起止日期

private string weekrange(system.datetime dt)
{
int weeknow = convert.toint32(dt.dayofweek);
int daydiff = (-1) * weeknow;
int dayadd = 6-weeknow;
string datebegin = system.datetime.now.adddays(daydiff).date.tostring("mm月dd日");
string dateend = system.datetime.now.adddays(dayadd).date.tostring("mm月dd日");
return datebegin + " - " +dateend;
}




收集最实用的网页特效代码!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表