ASP.NET HttpContext的时间戳属性
2011-07-30 02:40
267 查看
在ASP.NET框架,每一个HTTP请求到运行时将自动存储的时间戳。您可以通过timestamp属性,获得内容为一个DateTime支持字段DateTime值。在这里,我描述的HttpContext timestamp属性,并阐述它的一些细节。timestamp属性不读当前时间,它只能读取一个DateTime字段,在每个HTTP请求后自动存储的。因此,使用时间戳属性是速度远远超过使用DateTime.Now或以任何其他方式计算的时间。存储的时间戳属性的HttpContext类型的一个实例,是一个可以快速的方式得到一个请求到你的网站的启动时间。而不是访问的系统时钟,它会返回一个已经自动存储的DateTime值,这意味只是将几个字节复制到内存中,而不是任何时钟操作。因此,对于许多要求,时间戳属性的时间为导向的请求处理的理想选择。
// 具体时间:
Response.Write(Context.Timestamp.ToString() + "<br>");
//年月日:
Response.Write(Context.Timestamp.Date.ToString("D") + "<br>");
//年份:
Response.Write(Context.Timestamp.Year+ "<br>");
//月份:
Response.Write( Context.Timestamp.Month+ "<br>");
//日期部分:
Response.Write(Context.Timestamp.Date+ "<br>");
//日期号:
Response.Write( Context.Timestamp.Day+ "<br>");
//星期:
Response.Write( Context.Timestamp.DayOfWeek+ "<br>");
//一年中的第几天:
Response.Write( Context.Timestamp.DayOfYear+ "<br>");
//小時:
Response.Write( Context.Timestamp.Hour+ "<br>");
//毫秒:
Response.Write( Context.Timestamp.Millisecond+ "<br>");
//分:
Response.Write( Context.Timestamp.Minute+ "<br>");
//秒:
Response.Write(Context.Timestamp.Second + "<br>");
Ps:其实就是操作DateTime类型。
// 具体时间:
Response.Write(Context.Timestamp.ToString() + "<br>");
//年月日:
Response.Write(Context.Timestamp.Date.ToString("D") + "<br>");
//年份:
Response.Write(Context.Timestamp.Year+ "<br>");
//月份:
Response.Write( Context.Timestamp.Month+ "<br>");
//日期部分:
Response.Write(Context.Timestamp.Date+ "<br>");
//日期号:
Response.Write( Context.Timestamp.Day+ "<br>");
//星期:
Response.Write( Context.Timestamp.DayOfWeek+ "<br>");
//一年中的第几天:
Response.Write( Context.Timestamp.DayOfYear+ "<br>");
//小時:
Response.Write( Context.Timestamp.Hour+ "<br>");
//毫秒:
Response.Write( Context.Timestamp.Millisecond+ "<br>");
//分:
Response.Write( Context.Timestamp.Minute+ "<br>");
//秒:
Response.Write(Context.Timestamp.Second + "<br>");
Ps:其实就是操作DateTime类型。
相关文章推荐
- ASP.NET多线程下使用HttpContext.Current
- ASP.NET Core开发之HttpContext
- Asp.Net WebAPI 通过HttpContextBase获取请求参数
- 一:理解ASP.NET的运行机制(例:通过HttpModule来计算页面执行时间)
- ASP.NET HttpContext.Current在新建线程中会返回null
- [转]ASP.NET Core / MVC 6 HttpContext.Current
- asp.net 应用程序对象 HttpContext 和 HttpApplication (1)
- httpcontext in asp.net unit test
- 一:理解ASP.NET的运行机制(例:通过HttpModule来计算页面执行时间)
- ASP.NET Core开发之HttpContext
- Generating a new ASP.NET session in the current HTTPContext
- ASP.net:利用RowFilter属性,将一个DataSet绑定到两个DataGridhttp://www.ninedns.com/asp.net/2007430223347.html
- asp.net web api 开启HttpContext 的Session功能
- ASP.NET状态管理之四(暂存状态HttpContext.Items)
- asp.net 5 如何使用ioc 以及在如何获取httpcontext对象
- ASP.NET状态管理之四(暂存状态HttpContext.Items)
- 在ASP.NET Core中怎么使用HttpContext.Current
- ASP.NET MVC中HttpContext, HttpContextBase, HttpContextWrapper联系
- asp.net 中 HttpRequest 中跟URL path 有关的方法和属性
- ASP.NET多线程下使用HttpContext.Current为null解决方案 2015-01-22 15:23 349人阅读 评论(0) 收藏