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