为什么datetime.tryparseexact因“ jun&quot”而失败,但为其他所有其他人工作?
这是我非常简单的解析代码:
var us = new CultureInfo("en-US");
var dateToParse = "Jun 1";
var isSuccessful = DateTime.TryParseExact(dateToParse, "MMMM d", us, DateTimeStyles.None, out DateTime date);
出于某种原因,解析仅因“ jun”而失败。如果我解析“ 5月1日”(或我测试过的任何其他日期),则可以使用。另外,“ jun”是6月的正确3字母缩写。它甚至被列出在这里。
我在这里做错了什么?
解决方案: 感谢@damien_the_unbeliever。他指出我正在使用“ MMMM”而不是“ MMM”。愚蠢的错误。但是现在它有效。
Here's my very simple parsing code:
var us = new CultureInfo("en-US");
var dateToParse = "Jun 1";
var isSuccessful = DateTime.TryParseExact(dateToParse, "MMMM d", us, DateTimeStyles.None, out DateTime date);
For some reason, the parsing fails just for "Jun". If I parse "May 1" (or any other date I tested) it works. Also "Jun" is the correct 3 letter abbreviation for June. It's even listed here.
What am I doing wrong here?
Solution:
Thanks to @Damien_The_Unbeliever. He pointed out I was using "MMMM" instead of "MMM". Stupid mistake. But now it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案:
感谢@damien_the_unbeliever。他指出我正在使用“ MMMM”而不是“ MMM”。愚蠢的错误。但是现在它有效。
Solution:
Thanks to @Damien_The_Unbeliever. He pointed out I was using "MMMM" instead of "MMM". Stupid mistake. But now it works.