如何将日期字符串中的外国月份转换为英语 [英] How To Convert A Foreign Month In A Date String Into English

查看:62
本文介绍了如何将日期字符串中的外国月份转换为英语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面对另一个线程的回答似乎是我认为自己需要的一个开始,但是我在实现它时遇到了困难.

The below answer to another thread seems to make a start on what I think I need, but I am having difficulties in implementing it.

为此目的最好的库可能是Globalize.它允许您指定区域设置(称为文化,但实际相同),格式(内置或您自己的)以及实际将字符串解析为给定日期:

The best library for that purpose would probably be Globalize. It allows you to specify the locale (it is called culture but it is actually the same), the format (built-in or your own) and actually parse string to given date:

var dateString ="lunes,2011年2月29日";//似乎很长西班牙语中的日期格式var date = Globalize.parseDate(dateString,"D","es");

var dateString = "lunes, 29 de agosto de 2011"; // seems like long date format in Spanish var date = Globalize.parseDate( dateString, "D", "es" );

您需要附加适当的区域性文件以及参考全球化以使其发挥作用.请注意,文化已经在库中定义,所以不要害怕网络上的消息页面,您实际上不需要.Net.

You would need to attach appropriate culture file as well as reference to Globalize to make it work. Please mind that cultures are already defined in the library, so don't be afraid of the message on the web page, you actually don't need .Net.

如果有人可以把它变成一个可行的例子,那么我可以接受并适应我的需要.

If someone could turn this into a working example I could then take this and adjust to what I need.

但是...有人知道替代方法吗?

However ... does anyone know of an alternative method?

例如,我的字符串是:

"设置 2012年12月24日20:40:20",其中罗马尼亚语为月份.

"Set 24, 2012 20:40:20" which has the month in Romanian.

我需要成为

" 9月 2012年12月24日20:40:20",其中包含英语月份.

"Sep 24, 2012 20:40:20" which has the month in English.

我需要一个可以采用语言代码(即en,es,pl,ru,ro等)并在字符串中转换月份的解决方案(需要能够处理所有12个月,而不仅仅是处理月份中的一个)以上字符串)从外语到英语.

I need a solution that can take the language code (ie en, es, pl, ru, ro etc) and convert the month in the string (needs to be able to handle all 12 months, not just the one in the above string) from the foreign language to English.

我们将不胜感激,希望尽快提供帮助,以便我可以重新启动网站并再次全速运行.

Any speedy help would be most appreciated so that I can get my site back up and running at full speed again.

如果您需要我提供任何更多信息,请询问:)

If you require any further information from me please ask :)

问候罗斯

@Jukka K. Korpela

@Jukka K. Korpela

我有这个:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Testing Globalize</title>
<meta name="keywords" content="Globalize, Testing">
<meta name="description" content="Trying to get globalize to work.">
<script src="https://github.com/jquery/globalize/blob/master/lib/globalize.js"></script>
<script src="https://github.com/jquery/globalize/blob/master/lib/cultures/globalize.cultures.js"></script>
<script>
var monthString = 'sep'; // replace by code that extracts the string
var lang = 'ro';          // replace by code that picks up the right language
var month = Globalize.parseDate(monthString, 'MMM', lang);
if(month) {
  document.write(Globalize.format(month, 'MMM', 'en'));
} else {
  alert('Unrecognized month: ' + monthString);
}
</script>
</head>

但是当我在"http://htmledit.squarefree.com/"中进行测试时,它不起作用,请帮助:)

But it doesnt work when I test in "http://htmledit.squarefree.com/" please help :)

推荐答案

我认为您可以将datejs用于您的目的.它可以通过文化文件以任何可用的语言(状态为150+)解析日期数据,然后将其保存为英语或您想要的任何其他语言.

I think u could use datejs for your purpose. It is capable of parsing your date data in any language available (150+ as the state) via a culturefile and then save it in english or any other language you desire.

看看: http://code.google.com/p/datejs/

这篇关于如何将日期字符串中的外国月份转换为英语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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