简体   繁体   English

查找日期(所有语言)

[英]Find date (all languages)

I hit the issue when I need to find first occurrence of date in a html source. 当我需要在html源中查找第一次出现的日期时遇到了这个问题。 This can be "January 24, 2000" as well as 24 Januar 2000 (slovak language) or any other language date format. 可以是“ 2000年1月24日”,也可以是2000年1月24日(斯洛伐克语)或任何其他语言的日期格式。

you may know a library that would be able to do this. 您可能知道一个能够做到这一点的图书馆。 I don't, google didn't help :( 我不,谷歌没有帮助:(

I can't imagine how regex can do this as I would need to do a rule for all languages manually 我无法想象正则表达式如何做到这一点,因为我需要手动为所有语言制定规则

The CultureInfo class is what you're looking for. 您正在寻找CultureInfo类。 Use dt.ToString("D", c) to pass the cultureinfo and get your format(btw, same as dt.ToLongDateString ). 使用dt.ToString("D", c)传递cultureinfo并获取您的格式(btw,与dt.ToLongDateString相同)。

Have a look at the standard date and time format strings . 看看标准的日期和时间格式字符串

You can use CultureInfo.GetCultures to get all supported cultures. 您可以使用CultureInfo.GetCultures来获取所有受支持的文化。

DateTime dt = new DateTime(2000, 1, 24);
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
string allTranslatedJanuaries = 
    string.Join(Environment.NewLine, cultures.Select(c =>
        String.Format("{0}: {1}", c.EnglishName, dt.ToString("D", c))));

Here's a demo: http://ideone.com/6ypqJE 这是一个演示: http : //ideone.com/6ypqJE

On my server 352 cultures are installed, upon ideone only 112. 在我的服务器352上,仅在ideone上安装了区域性112。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM