AddDays() 到以 UTC 格式存储的日期时间
AddDays() to a DateTime stored in UTC
在 C#、MVC 5 中,如何对存储在 UTC
中的 DateTime
执行 AddDays()
函数?
这是我当前的代码:
DateTime testDateTime = DateTime.UtcNow;
testDateTime.AddDays(1);
testDateTime
不变。
我也试过这个:
DateTime testDateTime = DateTime.UtcNow;
DateTime testDateTimeKind = DateTime.SpecifyKind(testDateTime, DateTimeKind.Utc);
testDateTimeKind.AddDays(1);
testDateTimeKind
不变。
如何对存储在 UTC
中的 DateTime
执行 AddDays()
函数?
AddDays
returns 一个新的 DateTime
,因此您需要将返回值分配回您的变量,如下所示:
DateTime testDateTime = DateTime.UtcNow;
testDateTime = testDateTime.AddDays(1);
在 C#、MVC 5 中,如何对存储在 UTC
中的 DateTime
执行 AddDays()
函数?
这是我当前的代码:
DateTime testDateTime = DateTime.UtcNow;
testDateTime.AddDays(1);
testDateTime
不变。
我也试过这个:
DateTime testDateTime = DateTime.UtcNow;
DateTime testDateTimeKind = DateTime.SpecifyKind(testDateTime, DateTimeKind.Utc);
testDateTimeKind.AddDays(1);
testDateTimeKind
不变。
如何对存储在 UTC
中的 DateTime
执行 AddDays()
函数?
AddDays
returns 一个新的 DateTime
,因此您需要将返回值分配回您的变量,如下所示:
DateTime testDateTime = DateTime.UtcNow;
testDateTime = testDateTime.AddDays(1);