如何使用C#将datetime中英文文本中的月份名称转换为阿拉伯文本? [英] How to convert the month name in english text in datetime to arabic text using C#?

查看:76
本文介绍了如何使用C#将datetime中英文文本中的月份名称转换为阿拉伯文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




CultureInfo uiCulture1 = CultureInfo.CurrentUICulture; //'ar-AE' DateTime dDateTime2 = DateTime.Parse(dt.ToString(), uiCulture1, System.Globalization.DateTimeStyles.AssumeLocal); lblDate.Value = dt.ToString("dd MMMM yyyy");



推荐答案

我猜不同的是不同机器上的区域设置。

I'm guessing the difference is the regional settings on the different machines.

你确定CurrentUICulture在两台机器上实际上都是一样的吗?(我不熟悉阿拉伯语,所以有可能有几种变体吗?)。

Are you sure the CurrentUICulture is actually the same on both machines? (I'm not familiar with Arabic so is it possible there are several variants?).

你可以通过创建文化直接与:

You could test this by creating the culture directly with:

CultureInfo uiCulture1 = new CultureInfo("ar-AE");

你也可以在解析文本时将文化传递给'ToString()'方法(无论如何它应该是当前的文化,但如果在不同的机器上如上所述,它可以解释它可以解释不同的结果)。例如

You could also pass the culture to the 'ToString()' method when parsing to text (it should be picking up the current culture anyway, but if that is different on the different machines as suggested above it could explain the different results). e.g.

lblDate.Value = dt.ToString("dd MMMM yyyy", uiCulture1);


这篇关于如何使用C#将datetime中英文文本中的月份名称转换为阿拉伯文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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