01 | DateTime dt = DateTime.Now; |
02 | string [] strDT = new string [17]; |
03 | strDT[1] = dt.ToString(); |
04 | strDT[2] = dt.ToFileTime().ToString(); |
05 | strDT[3] = dt.ToFileTimeUtc().ToString(); |
06 | strDT[4] = dt.ToLocalTime().ToString(); |
07 | strDT[5] = dt.ToLongDateString().ToString(); |
08 | strDT[6] = dt.ToLongTimeString().ToString(); |
09 | strDT[7] = dt.ToOADate().ToString(); |
10 | strDT[8] = dt.ToShortDateString().ToString(); |
11 | strDT[9] = dt.ToShortTimeString().ToString(); |
12 | strDT[10] = dt.ToUniversalTime().ToString(); |
14 | strDT[1] = dt.Year.ToString(); |
15 | strDT[2] = dt.Date.ToString(); |
16 | strDT[3] = dt.DayOfWeek.ToString(); |
17 | strDT[4] = dt.DayOfYear.ToString(); |
18 | strDT[5] = dt.Hour.ToString(); |
19 | strDT[6] = dt.Millisecond.ToString(); |
20 | strDT[7] = dt.Minute.ToString(); |
21 | strDT[8] = dt.Month.ToString(); |
22 | strDT[9] = dt.Second.ToString(); |
23 | strDT[10] = dt.Ticks.ToString(); |
24 | strDT[11] = dt.TimeOfDay.ToString(); |
25 | strDT[1] = dt.ToString(); |
26 | strDT[2] = dt.AddYears(1).ToString(); |
27 | strDT[3] = dt.AddDays(1.1).ToString(); |
28 | strDT[4] = dt.AddHours(1.1).ToString(); |
29 | strDT[5] = dt.AddMilliseconds(1.1).ToString(); |
30 | strDT[6] = dt.AddMonths(1).ToString(); |
31 | strDT[7] = dt.AddSeconds(1.1).ToString(); |
32 | strDT[8] = dt.AddMinutes(1.1).ToString(); |
33 | strDT[9] = dt.AddTicks(1000).ToString(); |
34 | strDT[10] = dt.CompareTo(dt).ToString(); |
36 | strDT[1] = dt.Equals( "2009-2-28 16:11:04" ).ToString(); |
37 | strDT[2] = dt.Equals(dt).ToString(); |
38 | strDT[3] = dt.GetHashCode().ToString(); |
39 | strDT[4] = dt.GetType().ToString(); |
40 | strDT[5] = dt.GetTypeCode().ToString(); |
42 | strDT[1] = dt.GetDateTimeFormats( 's' )[0].ToString(); |
43 | strDT[2] = dt.GetDateTimeFormats( 't' )[0].ToString(); |
44 | strDT[3] = dt.GetDateTimeFormats( 'y' )[0].ToString(); |
45 | strDT[4] = dt.GetDateTimeFormats( 'D' )[0].ToString(); |
46 | strDT[5] = dt.GetDateTimeFormats( 'D' )[1].ToString(); |
47 | IFormatProvider culture = new System.Globalization.CultureInfo( "zh-CN" , true ); |
48 | strDT[6] = dt.GetDateTimeFormats( 'D' , culture)[2].ToString(); |
49 | strDT[7] = dt.GetDateTimeFormats( 'D' , culture)[3].ToString(); |
50 | strDT[8] = dt.GetDateTimeFormats( 'M' )[0].ToString(); |
51 | strDT[9] = dt.GetDateTimeFormats( 'f' )[0].ToString(); |
52 | strDT[10] = dt.GetDateTimeFormats( 'g' )[0].ToString(); |
53 | strDT[11] = dt.GetDateTimeFormats( 'r' )[0].ToString(); |
54 | strDT[1] = string .Format( "{0:d}" , dt); |
55 | strDT[2] = string .Format( "{0:D}" , dt); |
56 | strDT[3] = string .Format( "{0:f}" , dt); |
57 | strDT[4] = string .Format( "{0:F}" , dt); |
58 | strDT[5] = string .Format( "{0:g}" , dt); |
59 | strDT[6] = string .Format( "{0:G}" , dt); |
60 | strDT[7] = string .Format( "{0:M}" , dt); |
61 | strDT[8] = string .Format( "{0:R}" , dt); |
62 | strDT[9] = string .Format( "{0:s}" , dt); |
63 | strDT[10] = string .Format( "{0:t}" , dt); |
64 | strDT[11] = string .Format( "{0:T}" , dt); |
65 | strDT[12] = string .Format( "{0:u}" , dt); |
66 | strDT[13] = string .Format( "{0:U}" , dt); |
67 | strDT[14] = string .Format( "{0:Y}" , dt); |
68 | strDT[15] = string .Format( "{0}" , dt); |
69 | strDT[16] = string .Format( "{0:yyyyMMddHHmmssffff}" , dt); |
內文轉自http://www.dotblogs.com.tw/darren.net/archive/2009/03/06/datatimefunction.aspx