本文介绍了DateTime.TryParseExact不能使用预期的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下方法,我传递的值为07 Jan 2014 13:48:46,从我所了解的TryParseExact应该匹配格式dd MMM yyyy hh:mm:ss和返回true,但是它返回false,任何想法?
Hi I have the following method and I'm passing it the value "07 Jan 2014 13:48:46" and from what I understand the TryParseExact should be matching the format "dd MMM yyyy hh:mm:ss" and returning true, however it is returning false, any ideas?
string[] formats= {"dd-MM-yyyy hh:mm:ss", "dd MMM yyyy hh:mm:ss", "dd MMM yyyy", "hh-mm-ss", "dd-MM-yyyy", "dd-MM-yy", }; DateTime result; if (DateTime.TryParseExact(value, formats, CultureInfo.CurrentCulture, DateTimeStyles.None, out result)) { return result; } return null;推荐答案
24小时时间需要使用 HH ,而不是 hh 。小写 h 是12小时的时间。
24-hour time requires use of HH, not hh. Lowercase h is for 12 hour time.
请参阅: msdn.microsoft/en-us/library/8kb3ddd4%28v=vs.110 %29.aspx
更多推荐
DateTime.TryParseExact不能使用预期的字符串
发布评论