【发布时间】:2016-02-12 18:14:31
【问题描述】:
目前,当我在 outputTemplate 中使用{Timestamp} 时,它似乎是由DateTime.Now 生成的,因此属于DateTimeKind.Local 风格,因为当我给它一个“o”说明符时,它会产生类似于2016-02-12T09:51:34.4477761-08:00 的输出
对于上面的例子,我想得到的是2016-02-12T17:51:34.4477761Z,如果Timestamp 是DateTimeKind.Utc,就会产生它。
更新
看起来它实际上是DateTimeOffset that gets instantiated there,所以没有DateTimeKind 生效,而是看起来底层DateTime 总是DateTimeKind.Unspecified。 MSDN 注意到格式化 DateTimeOffset 与 DateTime 时的行为存在一些差异,特别是:
"u" -- 将 DateTimeOffset 值转换为 UTC 并使用格式 yyyy-MM-dd HH:mm:ssZ 输出。
转换正是我想要的,但我也需要分数。
【问题讨论】: