将日期时间格式转换为 UTC 日期时间格式 C# Biztalk 映射



我有一个字符串格式的日期时间,格式为 ( 2019-09-19T18:00:54.110 (

我想将上面的日期时间格式转换为UTC格式(yyyy/mm/dd hh:mm:ss(,这也是一种字符串格式,我无法弄清楚

感谢帮助!

这就是我到目前为止所做的,

public string FormatDate(string inputDate)
{
System.DateTime strDate;
if (System.DateTime.TryParseExact(inputDate, "yyyy-MM-ddTHH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out strDate))
{
return strDate.ToString("yyyy/MM/dd HH:mm:ss");
}
return "INVALID DATE";
}

您还需要使用f格式说明符指定毫秒。所以你最终会得到这样的东西:

yyyy-MM-ddTHH:mm:ss:fff

好吧,c#在DateTime上有很多惊人的函数。只需尝试:

var time = DateTime.Parse("2019 - 09 - 19T18: 00:54.110");
var result = time.ToUniversalTime().ToString("yyyy/mm/dd hh:mm:ss");

如果你想检查输入数据,添加一个try&catch块!

最新更新