C#日期解析精确MINDATE问题 [英] C# Date Parse Exact mindate issues
本文介绍了C#日期解析精确MINDATE问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下功能
DateTime fromDateParam = DateTime.ParseExact(Convert.ToString(DateTime.MinValue),"dd.MM.yyyy HH:mm:ss",null);
它说输入字符串未被识别为有效日期。
It says input string not recognised as a valid date.
任何想法我怎么能得到任何最小日确认为准确分析?
Any ideas how I can get any the min date recognised to parse exact?
推荐答案
那么你使用原来的时间转换为字符串的默认的格式,但你指定的自定义的格式的解析。
Well you're converting the original time to a string using the default formatting, but then you're specifying custom formatting for the parsing.
如果您在使用指定格式字符串则DateTime.ToString(格式)
并保持一致的格式,它工作正常:
If you specify a format string using DateTime.ToString(format)
and keep the format consistent, it works fine:
string formatString = "dd.MM.yyyy HH:mm:ss";
string text = DateTime.MinValue.ToString(formatString);
Console.WriteLine(text);
DateTime fromDateParam = DateTime.ParseExact(text, formatString, null);
这篇关于C#日期解析精确MINDATE问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文