如何将阿拉伯语(1430/01/30 yyyy / mm / dd)日期转换为英语farmat [英] How can I convert the arabic(1430/01/30 yyyy/mm/dd) date to english farmat

查看:459
本文介绍了如何将阿拉伯语(1430/01/30 yyyy / mm / dd)日期转换为英语farmat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将以下阿拉伯语日期转换为英语,那么我将面临异常(字符串未被识别为有效的日期时间)。请建议是否有任何解决方案。



如果我在谷歌转换器中做同样的话我在谷歌的答案是:2009年1月27日星期二



但我想用c#编码可以你帮我吗?



阿拉伯日期格式是:(1430/01/30 yyyy / mm / dd)



我尝试过:



if i convert the below Arabic date to English then i will face an exception(String was not recognized as a valid DateTime) .Please suggest if any solution for this.

If i am doing same in google converter then i got the answer in google is: 27 January, 2009 Tuesday

But i want to do in c# coding can you please help me??

arabic date formate is : (1430/01/30 yyyy/mm/dd)

What I have tried:

private void ConvertArabicDate()
        {
            string strArabicDate="14300130";
            string engDate = string.Empty;
            CultureInfo arCul = new CultureInfo("ar-SA");
            CultureInfo enCul = new CultureInfo("en-US");
            string[] allFormats = { "yyyy/MM/dd", "yyyy/M/d", "dd/MM/yyyy", "d/M/yyyy", "dd/M/yyyy", "d/MM/yyyy", "yyyy-MM-dd", "yyyy-M-d", "dd-MM-yyyy", "d-M-yyyy", "dd-M-yyyy", "d-MM-yyyy", "yyyy MM dd", "yyyy M d", "dd MM yyyy", "d M yyyy", "dd M yyyy", "d MM yyyy" };
            try
            {

                DateTime tempDate = DateTime.ParseExact(strArabicDate, allFormats, arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
                engDate = tempDate.ToString("dd-MMM-yyyy", enCul.DateTimeFormat);
            }
            catch (Exception ex)
            {
                 
               
                    engDate = "Unable to convert Arabic date ";
               
            }
        }

推荐答案

你非常接近,但你的输入字符串格式没有匹配你的所有格式格式。



你有yyyyMMdd中的日期没有出现在数组中。



除此之外,它看起来都很好
You're very close but your input string format does not match any of your allFormats formats.

You have the date in "yyyyMMdd" which does not appear in the array.

Other than that, it all looks fine


这篇关于如何将阿拉伯语(1430/01/30 yyyy / mm / dd)日期转换为英语farmat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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