Lea*_*ner 0 c# datetime localization
在DateTime.ParseExact使用Swedish(sv-SE)文化的方法的情况下,我观察到一些奇怪的行为.
我的计算机文化是,en-US但业务逻辑需要sv-SE文化.所以我先将它设置在当前线程上.
Thread.CurrentThread.CurrentUICulture = new CultureInfo("sv-SE");
Run Code Online (Sandbox Code Playgroud)
然后我执行以下操作来解析DateTime值.我想在这里解析的日期时间是2012年5月27日上午11:57.
DateTime.ParseExact("270512T11:57", "ddMMyyThh:mm", Thread.CurrentThread.CurrentUICulture);
Run Code Online (Sandbox Code Playgroud)
这很好用.
但是当我从晚上开始时,我得到了例外.当我尝试解析2012年5月27日晚上11:57的日期时间戳.
DateTime.ParseExact("270512T23:57", "ddMMyyThh:mm", Thread.CurrentThread.CurrentUICulture);
Run Code Online (Sandbox Code Playgroud)
上面的行给出了FormatException消息字符串未被识别为有效的DateTime..
这里真的有什么不对?