.ToUniversalTime() 在 DateTime 实例 (C#) 上到底做了什么?
What does .ToUniversalTime() really do on a DateTime instance (C#)?
以下 d、e、f 值之间的真正区别是什么? 'ToUniversalTime()' 的真正作用是什么?
var d = DateTime.Now;
var e = d.ToUniversalTime();
var f = e;
有人知道吗?谢谢
备注:当 'Created' 字段是日期时间 sql 字段且包含 UTC 时间时,我们检测到 EF 查询的差异:
var itemsD = ctx.Log.Where(p => p.Created > d);
var itemsE = ctx.Log.Where(p => p.Created > e);
ToUniversalTime 方法将本地小时的 DateTime 值转换为 UTC 小时。
如果要转换已知 UTC 值的时间值,可以使用此方法
"ToUniversalTime"方法返回的值由当前DateTime对象的"Kind"属性决定。下面描述可能的结果:
Kind: Utc
结果:未执行任何转换。
Kind: Local.
结果:当前 DateTime 对象转换为 UTC。
Kind: Unspecified.
结果:假设当前DateTime对象为本地时间,转换时Kind为本地时间。
默认为未指定。
The ToUniversalTime method converts a DateTime value from local time to UTC. To convert the time in a non-local time zone to UTC, use the TimeZoneInfo.ConvertTimeToUtc(DateTime, TimeZoneInfo) method. To convert a time whose offset from UTC is known, use the ToUniversalTime method.
以下 d、e、f 值之间的真正区别是什么? 'ToUniversalTime()' 的真正作用是什么?
var d = DateTime.Now;
var e = d.ToUniversalTime();
var f = e;
有人知道吗?谢谢
备注:当 'Created' 字段是日期时间 sql 字段且包含 UTC 时间时,我们检测到 EF 查询的差异:
var itemsD = ctx.Log.Where(p => p.Created > d);
var itemsE = ctx.Log.Where(p => p.Created > e);
ToUniversalTime 方法将本地小时的 DateTime 值转换为 UTC 小时。 如果要转换已知 UTC 值的时间值,可以使用此方法
"ToUniversalTime"方法返回的值由当前DateTime对象的"Kind"属性决定。下面描述可能的结果:
Kind: Utc
结果:未执行任何转换。
Kind: Local.
结果:当前 DateTime 对象转换为 UTC。
Kind: Unspecified.
结果:假设当前DateTime对象为本地时间,转换时Kind为本地时间。
默认为未指定。
The ToUniversalTime method converts a DateTime value from local time to UTC. To convert the time in a non-local time zone to UTC, use the TimeZoneInfo.ConvertTimeToUtc(DateTime, TimeZoneInfo) method. To convert a time whose offset from UTC is known, use the ToUniversalTime method.