DateTime - .NET时间数据及输出格式

整理一下.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());
}
}
}

/*
========= Fields =========
Year 2018
Month 2
Date 2/27/2018 12:00:00 AM
Day 27
DayOfWeek Tuesday
DayOfYear 58
Kind Local
Minute 27
Second 51
Millisecond 54
Ticks 636553276710549486
========= Methods =========
ToBinary -8586819048144226322
ToFileTime 131641756710549486
ToFileTimeUtc 131641756710549486
ToLocalTime 2/27/2018 11:27:51 AM
ToLongDateString Tuesday, February 27, 2018
ToLongTimeString 11:27:51 AM
ToOADate 43158.4776742361
ToShortDateString 2/27/2018
ToShortTimeString 11:27 AM
ToString 2/27/2018 11:27:51 AM
ToUniversalTime 2/27/2018 3:27:51 AM
Press any key to continue . . .
*/