- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尽管执行了 ToString(),但我在调试时遇到此错误:
A UTC DateTime is being converted to text in a format that is only correct for local times. This can happen when calling DateTime.ToString using the 'z' format specifier, which will include a local time zone offset in the output. In that case, either use the 'Z' format specifier, which designates a UTC time, or use the 'o' format string, which is the recommended way to persist a DateTime in text. This can also occur when passing a DateTime to be serialized by XmlConvert or DataSet. If using XmlConvert.ToString, pass in XmlDateTimeSerializationMode.RoundtripKind to serialize correctly. If using DataSet, set the DateTimeMode on the DataColumn object to DataSetDateTime.Utc.
public static string ToInterfaceString(this DateTime value)
{
return value != DateTime.MinValue ? value.ToString("yyyy-MM-ddTHH:mm:sszzz") : string.Empty;
}
在我刚刚开始开发的应用程序中,很多地方都使用了这种格式。那我实际上应该怎么办呢?将 zzz 替换为 Z?
更新 1:传递到我的扩展程序的 DateTime 被初始化为:
DateTimeCreated = DateTime.UtcNow;
奇怪的是,如果我将一些其他 DateTime 对象传递给此扩展程序,我不会收到任何错误/警告。
最佳答案
这只是一个绿色警告。
因此 - 因为您似乎知道自己在做什么 - 您可以理解消息(这是正确的)并标记复选框以以后忽略此警告。
关于c# - 如何解决 DateTimeInvalidLocalFormat 错误 : "A UTC DateTime is being converted to text in a format that is only correct for local times."?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33346052/
我是一名优秀的程序员,十分优秀!