- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Datetime : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- TodayInfo();
- Response.Write( "<br/>");
- NowInfo();
- }
- //datetome.today
- private void TodayInfo()
- {
- //用Today屬性 時間上都是預設12:00:00
- //取得今天是星期幾
- Response.Write("Today.DayOfWeek : " + DateTime.Today.DayOfWeek.ToString() + "<br/>");
- //今天是今年的第幾天
- Response.Write("Today.DayOfYear : " + DateTime.Today.DayOfYear.ToString() + "<br/>");
- //取得今天日期
- //Response.Write("Today.Date : "+DateTime.Today.Date + "<br/>");
- //結果同上
- //Response.Write("Today : "+DateTime.Today + "<br/>");
- //短日期 無時間
- //長日期 有國字年月日 無時間
- Response.Write("Today.ToLongDateString : " + DateTime.Today.ToLongDateString() + "<br/>");
- //短時間 無秒數
- // Response.Write("Today.ToShortTimeString : " + DateTime.Today.ToShortTimeString() + "<br/>");
- //長時間
- //Response.Write("Today.ToLongTimeString : " + DateTime.Today.ToLongTimeString() + "<br/>");
- //現在月份
- Response.Write("Today.Month : " + DateTime.Today.Month + "<br/>");
- //日期+36天
- Response.Write("Today.AddDays(36) : " + DateTime.Today.AddDays(36).ToLongDateString() + "<br/>");
- //日期+36天並轉成星期幾
- Response.Write("Today.AddDays(36) : " + DateTime.Today.AddDays(36).DayOfWeek.ToString() + "<br/>");
- //加時間 TimeSpan(天,時,分,秒)
- Response.Write("Today.Add(new TimeSpan(30, 0, 0, 0) " + DateTime.Today.Add(new TimeSpan(30, 0, 0, 0)) + "<br/>");
- //windows檔案時間
- Response.Write("Today.ToFileTime().ToString() : " + DateTime.Today.ToFileTime().ToString() + "<br/>");
- // 根據哪邊時間
- Response.Write("Today.Kind : " + DateTime.Today.Kind + "<br/>");
- }
- //datetime.now
- private void NowInfo()
- {
- //Now 才能顯示正確時間
- Response.Write("Now : " + DateTime.Now.ToString() + "<br/>");
- //顯示時間
- Response.Write("Now.ToLongTimeString() : " + DateTime.Now.ToLongTimeString() + "<br/>");
- Response.Write("Now.ToShortTimeString() : " + DateTime.Now.ToShortTimeString() + "<br/>");
- //顯示日期
- Response.Write("Now.ToLongDateString() : " + DateTime.Now.ToLongDateString() + "<br/>");
- Response.Write("Now.ToShortDateString() : " + DateTime.Now.ToShortDateString() + "<br/>");
- Response.Write("Now : " + DateTime.Now.Hour + "<br/>");
- }
- }
2014年1月6日 星期一
[C#] DateTime 練習
使用簡易的Today 與 Now 做練習
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言