DateTimeFormat.AbbreviatedMonthNames在月份名称的末尾添加一个点 [英] DateTimeFormat.AbbreviatedMonthNames adding a dot at the end of month's name

查看:216
本文介绍了DateTimeFormat.AbbreviatedMonthNames在月份名称的末尾添加一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨晚,我们将Web服务层从物理Windows 2008 r2迁移到虚拟Windows2012。

Last night we migrated our web services tier from physical Windows 2008 r2 to virtual Windows 2012.

我们在日志中收到大量有关DateTime无效格式的事件,

We are getting tons of events on ours logs about DateTime's invalid formats, strange as we double checked our regional settings.

长话短说:

CultureInfo.GetCultureInfo("es-MX").DateTimeFormat.AbbreviatedMonthNames

输出(使用LinqPad5) :

Outputs (using LinqPad5):


  1. ene。

  2. feb。

  3. mar。

在我们新的2012年环境中,而在2008年的时候:

on our new 2012 env while on 2008 ouptus:


  1. ene

  2. feb

  3. mar

我们的解析是这样的:

DateTime.Parse("18 ene 16",CultureInfo.GetCultureInfo("es-MX"))

虽然它发挥了作用,但现在它抛出了

And while it worked wonders now it throws

FormatException:
无法将字符串识别为有效的DateTime。从索引3开始有一个未知词。

FormatException : The string was not recognized as a valid DateTime. There is an unknown word starting at index 3..

DateTime.Parse("18 ene. 16",CultureInfo.GetCultureInfo("es-MX"))

可以工作,但不是我们几个客户的预期输入。

works but isn't the expected input from our several clients.

使用相同的运行时版本(4.0.30319.42000),需加倍(再次)检查了两台服务器上的区域设置(在放弃并使用正则表达式替换并对其进行黑客攻击之前),我还能寻找什么来解决此问题?

Working on the same runtime version (4.0.30319.42000), double checked (again) our regional settings on both servers what else can I look for to fix this (before giving up and hacking it with a regex replace)?

谢谢。 / p>

Thanks.

推荐答案

遗憾的是,我在配置中找不到任何指向正确方向的东西。

Sadly I couldn't find anything in the configuration that pointed me in the right direction.

以这样的讨厌的hack结尾:

Ended with a nasty hack like this:

var cultura = CultureInfo.CreateSpecificCulture("es-MX");
if (cultura.DateTimeFormat.AbbreviatedMonthNames.First().EndsWith("."))
   cultura.DateTimeFormat.AbbreviatedMonthNames = cultura.DateTimeFormat.AbbreviatedMonthNames.Select(c => c.Substring(0, c.Length > 1 ? c.Length - 1 : 0)).ToArray();

并在分析中使用了这种文化。

and used that culture in the parsing.

这篇关于DateTimeFormat.AbbreviatedMonthNames在月份名称的末尾添加一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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