[C#.NET][VB.NET] 日期 與 時間

  • 40379
  • 0
  • C#
  • 2009-06-11

[C#.NET][VB.NET] 日期 與 時間

DateTime 結構,提供了有關日期時間的方法和屬性,我們可以利用它來取得有關於日期時間的訊息。

為了不讓自己忘記便記錄了

DateTime myDtae = DateTime.Now; 
 
this.listBox1.Items.Add("ToBinary: " + myDtae.ToBinary().ToString());
this.listBox1.Items.Add("ToFileTime: " + myDtae.ToFileTime().ToString());
this.listBox1.Items.Add("ToFileTimeUtc: " + myDtae.ToFileTimeUtc().ToString());
this.listBox1.Items.Add("ToLocalTime: " + myDtae.ToLocalTime().ToString());
this.listBox1.Items.Add("ToLongDateString: " + myDtae.ToLongDateString().ToString());
this.listBox1.Items.Add("ToLongTimeString: " + myDtae.ToLongTimeString().ToString());
this.listBox1.Items.Add("ToOADate: " + myDtae.ToOADate().ToString());
this.listBox1.Items.Add("ToShortDateString: " + myDtae.ToShortDateString().ToString());
this.listBox1.Items.Add("ToShortTimeString: " + myDtae.ToShortTimeString().ToString());
this.listBox1.Items.Add("ToString: " + myDtae.ToString().ToString());
this.listBox1.Items.Add("ToUniversalTime: " + myDtae.ToUniversalTime().ToString());
this.listBox1.Items.Add("Year: " + myDtae.Year.ToString());
this.listBox1.Items.Add("Month: " + myDtae.Month.ToString());
this.listBox1.Items.Add("Date: " + myDtae.Date.ToString());
this.listBox1.Items.Add("Day: " + myDtae.Day.ToString());
this.listBox1.Items.Add("Hour: " + myDtae.Hour.ToString());
this.listBox1.Items.Add("Minute: " + myDtae.Minute.ToString());
this.listBox1.Items.Add("Millisecond: " + myDtae.Millisecond.ToString());
this.listBox1.Items.Add("DayOfWeek: " + myDtae.DayOfWeek.ToString());
this.listBox1.Items.Add("DayOfYear: " + myDtae.DayOfYear.ToString());
this.listBox1.Items.Add("TimeOfDay: " + myDtae.TimeOfDay.ToString());
this.listBox1.Items.Add("Kind: " + myDtae.Kind.ToString());
this.listBox1.Items.Add("Ticks: " + myDtae.Ticks.ToString());
this.listBox1.Items.Add("===============================================");
this.listBox1.Items.Add("AddDays(5): " + myDtae.AddDays(5).ToString());
this.listBox1.Items.Add("AddHours(5): " + myDtae.AddHours(5).ToString());
this.listBox1.Items.Add("AddMilliseconds(5): " + myDtae.AddMilliseconds(5).ToString());
this.listBox1.Items.Add("AddMinutes(5): " + myDtae.AddMinutes(5).ToString());
this.listBox1.Items.Add("AddMonths(5): " + myDtae.AddMonths(5).ToString());
this.listBox1.Items.Add("AddSeconds(5): " + myDtae.AddSeconds(5).ToString());
this.listBox1.Items.Add("AddTicks(5): " + myDtae.AddTicks(5).ToString());
this.listBox1.Items.Add("AddYears(5): " + myDtae.AddYears(5).ToString());
this.listBox1.Items.Add("GetDateTimeFormats: " + myDtae.GetDateTimeFormats());
this.listBox1.Items.Add("GetType: " + myDtae.GetType().ToString());
this.listBox1.Items.Add("GetTypeCode: " + myDtae.GetTypeCode().ToString());
this.listBox1.Items.Add("IsDaylightSavingTime: " + myDtae.IsDaylightSavingTime().ToString());
this.listBox1.Items.Add("Subtract: " + myDtae.Subtract(DateTime.Now).ToString());
String s = myDtae.ToLocalTime().ToString();
this.listBox1.Items.Add("Parse: " + DateTime.Parse(s));

快照-20093116124

 

VB與C#範例下載:日期時間方法.rar

若有謬誤,煩請告知,新手發帖請多包涵


Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET

Image result for microsoft+mvp+logo