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

     

  • 相关阅读:
    Python3 使用requests库读取本地保存的cookie文件实现免登录访问
    Python3 使用requests库登陆知乎并保存cookie为本地文件
    python中的ConfigParser模块
    python中json的使用
    python中的IO模块
    python中的apscheduler模块
    ubuntu14静态ip配置
    在ubuntu14中搭建邮箱服务器
    python 生成器
    python中列表生成式
  • 原文地址:https://www.cnblogs.com/gengaixue/p/2121690.html
Copyright © 2011-2022 走看看