DateTime.TryParseExact不能使用预期的字符串

编程入门 行业动态 更新时间:2024-10-18 03:22:25
本文介绍了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不能使用预期的字符串

本文发布于:2023-11-07 19:41:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567244.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   DateTime   TryParseExact

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!