zoukankan
html css js c++ java
C#关于日期月天数和一年有多少周及某年某周时间段的计算
/**/
///
<summary>
///
当前月有多少天
///
</summary>
///
<param name="y"></param>
///
<param name="m"></param>
///
<returns></returns>
public
static
int
HowMonthDay(
int
y,
int
m)
{
int
mnext;
int
ynext;
if
(m
<
12
)
{
mnext
=
m
+
1
;
ynext
=
y;
}
else
{
mnext
=
1
;
ynext
=
y
+
1
;
}
DateTime dt1
=
System.Convert.ToDateTime(y
+
"
-
"
+
m
+
"
-1
"
);
DateTime dt2
=
System.Convert.ToDateTime(ynext
+
"
-
"
+
mnext
+
"
-1
"
);
TimeSpan diff
=
dt2
-
dt1;
return
diff.Days;
}
/**/
///
<summary>
///
得到一年中的某周的起始日和截止日
///
年 nYear
///
周数 nNumWeek
///
周始 out dtWeekStart
///
周终 out dtWeekeEnd
///
</summary>
///
<param name="nYear"></param>
///
<param name="nNumWeek"></param>
///
<param name="dtWeekStart"></param>
///
<param name="dtWeekeEnd"></param>
public
static
void
GetWeek(
int
nYear,
int
nNumWeek,
out
DateTime dtWeekStart,
out
DateTime dtWeekeEnd)
{
DateTime dt
=
new
DateTime(nYear,
1
,
1
);
dt
=
dt
+
new
TimeSpan((nNumWeek
-
1
)
*
7
,
0
,
0
,
0
);
dtWeekStart
=
dt.AddDays(
-
(
int
)dt.DayOfWeek
+
(
int
)DayOfWeek.Monday);
dtWeekeEnd
=
dt.AddDays((
int
)DayOfWeek.Saturday
-
(
int
)dt.DayOfWeek
+
1
);
}
/**/
///
<summary>
///
求某年有多少周
///
返回 int
///
</summary>
///
<param name="strYear"></param>
///
<returns>
int
</returns>
public
static
int
GetYearWeekCount(
int
strYear)
{
string
returnStr
=
""
;
System.DateTime fDt
=
DateTime.Parse(strYear.ToString()
+
"
-01-01
"
);
int
k
=
Convert.ToInt32(fDt.DayOfWeek);
//
得到该年的第一天是周几
if
(k
==
1
)
{
int
countDay
=
fDt.AddYears(
1
).AddDays(
-
1
).DayOfYear;
int
countWeek
=
countDay
/
7
+
1
;
return
countWeek;
}
else
{
int
countDay
=
fDt.AddYears(
1
).AddDays(
-
1
).DayOfYear;
int
countWeek
=
countDay
/
7
+
2
;
return
countWeek;
}
}
/**/
///
<summary>
///
求当前日期是一年的中第几周
///
</summary>
///
<param name="date"></param>
///
<returns></returns>
public
static
int
WeekOfYear(DateTime curDay)
{
int
firstdayofweek
=
Convert.ToInt32(Convert.ToDateTime(curDay.Year.ToString()
+
"
-
"
+
"
1-1
"
).DayOfWeek);
int
days
=
curDay.DayOfYear;
int
daysOutOneWeek
=
days
-
(
7
-
firstdayofweek);
if
(daysOutOneWeek
<=
0
)
{
return
1
;
}
else
{
int
weeks
=
daysOutOneWeek
/
7
;
if
(daysOutOneWeek
%
7
!=
0
)
weeks
++
;
return
weeks
+
1
;
}
}
查看全文
相关阅读:
DSOFramer的使用(一)
正试图在 os 加载程序锁内执行托管代码
在Net中javascript获取Request的值
DSOFramer的使用(二)
FreeTextBox使用
编译C#项目时报”LC.exe已退出“错误
(转)QueryADataset
DLR的几篇实践编译器的文章
部署vs 2008 Report View
强烈推荐SQL Prompt 3.8,并发布SQL Prompt 3.8 ,SQL Refator 的xxx
原文地址:https://www.cnblogs.com/skyblue/p/967455.html
最新文章
深入解析AsyncTask
Matrix.postScale
下拉刷新 左右滑动
ubuntu代理登录webqq失败
open log device
VisualSVN Server service failed
asp.net获取mac(终)
js操作dataset以及datatable(记录一下老是忘记)
js获取mac地址(续)
vs.net 不积跬步无以至千里
热门文章
什么样的女人才是老婆(感动)
asp.net获取客户端ip
youtube下载视频连带转换 速度超快
多个IP、端口、MAC地址的正则匹配
asp.net 获取服务器的硬盘id 网卡mac地址 cpu序列号
js数组 sort方法的分析
取得GridPanel选定行所有字段值
Net获取当前的URL
关于引用DLL后,生成应用程序时找不到相应方法
插件式应用程序构建系列
Copyright © 2011-2022 走看看