更好的DateTime.Parse在那里?
问题描述:
有人知道那里的一个库(收费的或不收费的)能够处理比DateTime.Parse使用的更常见的datetime格式吗?可以在几天/几个月内处理多种语言和缩写的东西真的很棒.
Does anyone know of a library (paid or not) out there that is able to handle more common datetime formats than DateTime.Parse uses? Something that can handle multiple languages and abbreviations for days/months would be really nice.
例如:"2009年9月1日"不适用于Datetime.Parse.
For example: "Sept 1, 2009" does not work with Datetime.Parse.
答
要使用非标准缩写解析日期,您需要创建自己的文化.
To parse dates with non-standard abbreviations, you'll need to create your own culture.
例如:(已测试)
var culture = new CultureInfo("en-US");
culture.DateTimeFormat.AbbreviatedMonthNames = new string[] {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec", ""
};
DateTime.Parse("Sept 1, 2009", culture);