加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 使用FileHelpers将DateTime格式化为UTC

发布时间:2020-12-16 01:38:45 所属栏目:百科 来源:网络整理
导读:我有一个记录,我使用FileHelpers写出CSV文件.我希望将结构的DateTime字段写为UTC日期.我目前有以下格式化程序: [FieldConverter(ConverterKind.Date,"yyyy-MM-dd")] 要让它输出UTC日期,我需要做什么? 解决方法 医生说: You can check all the supported f
我有一个记录,我使用FileHelpers写出CSV文件.我希望将结构的DateTime字段写为UTC日期.我目前有以下格式化程序:

[FieldConverter(ConverterKind.Date,"yyyy-MM-dd")]

要让它输出UTC日期,我需要做什么?

解决方法

医生说:

You can check all the supported format
strings check the MSDN docs for
DateTime.ParseExact

所以根据:http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

[FieldConverter(ConverterKind.Date,“u”)]

“你”=> “yyyy’ – ‘MM’ – ‘dd HH’:??’mm’:’ss’Z’”
它不会将日期转换为utc,只需格式化即可

您仍然需要DateTime.ToUniversalTime来转换它.

编辑
如果你有类似的东西:

[FieldConverter(ConverterKind.Date,"ddMMyyyy" )]
public DateTime ShippedDate;

然后添加一个临时ShippedDateUTC:

public DateTime ShippedDate;

[FieldConverter(ConverterKind.Date,"ddMMyyyy" )]
public DateTime ShippedDateUTC {
  get{ return ShippedDate.ToUniversalTime();}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读