当前位置:跳过导航链接计算机毕业设计首页 : 技术应用 : 详细内容

ASP.NET常见日期使用方法汇总

来源:转载 作者:管理员 添加时间:2011-08-29 点击数:15966

在利用c#,asp.net开发程序时,经常会用到计算日期的相关问题,例如计算当月天数、日期格式类型设置、周六、日在第几天等等下面的文章就是经过近阶段的积累,然后与读者进行分享:

一.如何获得当月有多少天

int m=System.DateTime.DaysInMonth(System.DateTime.Now.Year,System.DateTime.Now.Month);

二.日期型格式处理通用方法
1.在webconfig中配置如下

<add key="ShortDatePattern" value="MM-dd-yyyy" />
<add key="LongDatePattern" value="dddd-MMMM dd-yyyy" />
<add key="ShortTimePattern" value="hh:mm tt" />
<add key="LongTimePattern" value="hh:mm tt" />

2.在global.asax中

protected void Application_BeginRequest(Object sender, EventArgs e)
{
Thread currentThread 
=
 Thread.CurrentThread;
CultureInfo cul 
= currentThread.CurrentCulture.Clone() as
 CultureInfo;
cul.DateTimeFormat.ShortDatePattern
=
 BLLFacade.Common.GetShortDatePattern();
cul.DateTimeFormat.LongDatePattern
=
 BLLFacade.Common.GetLongDatePattern();
cul.DateTimeFormat.ShortTimePattern
=
 BLLFacade.Common.GetShortTimePattern();
cul.DateTimeFormat.LongTimePattern
=
 BLLFacade.Common.GetLongTimePattern();
currentThread.CurrentCulture 
=
 cul;
}

第1页第2页第3页第4页第5页

【联系方式】

【本站信誉】

用心做计算机毕业设计论文网