ASP.NET HttpContext的時間戳記屬性

來源:互聯網
上載者:User

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

 

相關關鍵詞:
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.