回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,61 +1,31 @@
|
|
1
1
|
今の時間が何時でもいいように`.Date`してから引き算、`TimeSpan`の`.Days`が目的の数値です。
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
```
|
3
|
+
```cs
|
6
|
-
|
7
4
|
private void button1_Click(object sender, EventArgs e)
|
8
|
-
|
9
5
|
{
|
10
|
-
|
11
6
|
DateTime dateTime1 = DateTime.Now;
|
12
|
-
|
13
7
|
DateTime dateTime2 = new DateTime(2020, 4, 25);
|
14
8
|
|
15
|
-
|
16
|
-
|
17
9
|
TimeSpan result = dateTime2.Date - dateTime1.Date;
|
18
|
-
|
19
10
|
int days = result.Days;
|
20
|
-
|
21
11
|
label1.Text = days.ToString(); // 6
|
22
|
-
|
23
12
|
}
|
24
|
-
|
25
13
|
```
|
26
14
|
|
27
|
-
|
28
|
-
|
29
|
-
```
|
15
|
+
```cs
|
30
|
-
|
31
16
|
private void button1_Click(object sender, EventArgs e)
|
32
|
-
|
33
17
|
{
|
34
|
-
|
35
18
|
DateTimeOffset dateTimeOffset1 = DateTimeOffset.Now;
|
36
19
|
|
37
|
-
|
38
|
-
|
39
20
|
// どれも 2020/04/10 0:00:00 +09:00
|
40
|
-
|
41
21
|
//DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2020, 4, 10, 0, 0, 0), TimeSpan.FromHours(9));
|
42
|
-
|
43
22
|
//DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2020, 4, 10, 0, 0, 0, DateTimeKind.Local));
|
44
|
-
|
45
23
|
DateTimeOffset dateTimeOffset2 = new DateTimeOffset(new DateTime(2020, 4, 10, 0, 0, 0));
|
46
|
-
|
47
24
|
|
48
|
-
|
49
25
|
TimeSpan result = dateTimeOffset2.Date - dateTimeOffset1.Date;
|
50
|
-
|
51
26
|
int days = result.Days;
|
52
|
-
|
53
27
|
label1.Text = days.ToString(); // -9
|
54
|
-
|
55
28
|
}
|
56
|
-
|
57
29
|
```
|
58
30
|
|
59
|
-
|
60
|
-
|
61
31
|
日本時間で計算するんですよね?
|