整理一下.NET下,DateTime实例所包含的时间数据,以及默认支持的时间输出格式
DateTime -
.NET时间数据及输出格式
1 example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| using System;
namespace DateTimeTest { class DateTimeTest { static void Main(string[] args) { var dt = DateTime.Now;
Console.WriteLine("========= Fields ========="); Console.WriteLine("Year\t\t" + dt.Year); Console.WriteLine("Month\t\t" + dt.Month); Console.WriteLine("Date\t\t" + dt.Date); Console.WriteLine("Day\t\t" + dt.Day); Console.WriteLine("DayOfWeek\t\t" + dt.DayOfWeek); Console.WriteLine("DayOfYear\t\t" + dt.DayOfYear); Console.WriteLine("Kind\t\t" + dt.Kind); Console.WriteLine("Minute\t\t" + dt.Minute); Console.WriteLine("Second\t\t" + dt.Second); Console.WriteLine("Millisecond\t\t" + dt.Millisecond); Console.WriteLine("Ticks\t\t" + dt.Ticks);
Console.WriteLine("========= Methods ========="); Console.WriteLine("ToBinary\t\t" + dt.ToBinary()); Console.WriteLine("ToFileTime\t\t" + dt.ToFileTime()); Console.WriteLine("ToFileTimeUtc\t\t" + dt.ToFileTimeUtc()); Console.WriteLine("ToLocalTime\t\t" + dt.ToLocalTime()); Console.WriteLine("ToLongDateString\t" + dt.ToLongDateString()); Console.WriteLine("ToLongTimeString\t" + dt.ToLongTimeString()); Console.WriteLine("ToOADate\t\t" + dt.ToOADate()); Console.WriteLine("ToShortDateString\t" + dt.ToShortDateString()); Console.WriteLine("ToShortTimeString\t" + dt.ToShortTimeString()); Console.WriteLine("ToString\t\t" + dt.ToString()); Console.WriteLine("ToUniversalTime\t\t" + dt.ToUniversalTime()); } } }
|