方法 TryParseExact
在下面收益code座真
。
我想知道这是为什么。
我认为,这个日期2013年3月12日
是无效的,因为这不是由斜线,但点分开。
在我改变了的CultureInfo
反德
到EN-US
,该方法返回假
。这可能是一个暗示,但我仍然不知道为什么会这样。
VAR格式=新的String [] {YYYY / MM / DD};
VAR分析=新的日期时间();
VAR的结果= DateTime.TryParseExact(2013年3月12号,格式,
新的CultureInfo(去-DE),DateTimeStyles.None,出解析);
解决方案
我觉得你现在的 DateSeparator
是。
(点)和 /
全自动本身代替它。
/
分隔符有特殊的意义的与当前区域性的日期分隔符代替我的
CultureInfo的C =新的CultureInfo(去DE);
Console.WriteLine(c.DateTimeFormat.DateSeparator); //打印。 (点)
看看的/
自定义格式说明
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.
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);
解决方案
I think your current DateSeparator
is .
(dot) and /
automaticly replace itself to it.
/
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
相关推荐
最新文章