TryParseExact返回false,虽然我不知道为什么 [英] TryParseExact returns false, though I don't know why

查看:235
本文介绍了TryParseExact返回false,虽然我不知道为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法 TryParseExact 在下面的代码块中返回 true

我想知道为什么。

我认为这个日期2013.03.12是无效的,因为这不是由斜线分隔,而是点。

Method TryParseExact in code block below returns true.
I would like to know why.
I think this date "2013.03.12" is invalid because this is not separated by slash but dot.

将$ code> CultureInfo de-De更改为en-US,该方法返回 false 。这可能是一个提示,但我仍然不知道为什么会发生这种情况。

After I changed the CultureInfo "de-De" to "en-US", the method returns false. This could be a hint but I still don't know why this happens.

var format = new string[] { "yyyy/MM/dd" };
var parsed = new DateTime();
var result = DateTime.TryParseExact("2013.03.12", format, 
             new CultureInfo("de-DE"), DateTimeStyles.None, out parsed);


推荐答案

我认为你目前的 DateSeparator (点)和 / 自动替换为

I think your current DateSeparator is . (dot) and / automaticly replace itself to it.

/ seperator具有替换当前文化日期分隔符

/ seperator has a special meaning of "replace me with the current culture's date separator"

CultureInfo c = new CultureInfo("de-DE");
Console.WriteLine(c.DateTimeFormat.DateSeparator); //Prints . (dot)

查看 /自定义格式说明符

Take a look at The "/" Custom Format Specifier

这篇关于TryParseExact返回false,虽然我不知道为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆