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

     

  • 相关阅读:
    BZOJ3098 Hash Killer II 【概率】
    BZOJ4010 [HNOI2015]菜肴制作 【拓扑排序 + 贪心】
    洛谷P4364 [九省联考2018]IIIDX 【线段树】
    洛谷P4363 [九省联考2018]一双木棋chess 【状压dp】
    洛谷P2664 树上游戏 【点分治 + 差分】
    BZOJ1189 [HNOI2007]紧急疏散evacuate 【二分 + 网络流】
    BZOJ1068 [SCOI2007]压缩 【区间dp】
    BZOJ4033 [HAOI2015]树上染色 【树形dp】
    BZOJ4819 [Sdoi2017]新生舞会 【01分数规划 + 费用流】
    排序
  • 原文地址:https://www.cnblogs.com/gengaixue/p/2121690.html
Copyright © 2011-2022 走看看