zoukankan      html  css  js  c++  java
  • ASP.NET HttpContext的时间戳属性

    在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类型。

     

  • 相关阅读:
    C语言的指针
    C语言的编译过程和GCC编译参数
    GCC编译器的安装
    全字段多条件搜索(api接口)
    C# Replace字符替换函数
    NetCore MemoryCache使用
    vs2017 C# ActiveX浏览器插件 创建 发布 C# windows窗体控件库(.NET Framework)注意事项
    [Asp.net core 3.1] 通过一个小组件熟悉Blazor服务端组件开发
    [AspNetCore 3.0 ] Blazor 服务端组件 Render, RenderFragment ,RenderTreeBuilder, CascadingValue/CascadingParameter 等等
    [AspNetCore 3.0] 在RazorPages/MVC 中使用 Blazor (Razor组件)
  • 原文地址:https://www.cnblogs.com/gengaixue/p/2121690.html
Copyright © 2011-2022 走看看