从网络服务获取奇怪的日期格式,我想知道如何将其解析为正常的日期时间。
服务结果:01-05T09:55
(MM-dd 时间)
由于该字符串没有年份,因此在 DateTime.Parse
中失败。
有什么想法如何在不使用字符串函数操作的情况下获取当前年份吗?
最佳答案
尝试DateTime.ParseExact并提供格式:
string source = "01-05T09:55";
// 5 Jan 2017 (current year) 9:55
DateTime result = DateTime.ParseExact(source, "M-d'T'H:m", CultureInfo.InvariantCulture);
关于C# Date Parse 非标准日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47925617/