Friday, May 30, 2014

convert dates gregorian to Umalqura and opposite sample funciton

the function take date with format yyyy-MM-dd and language ar or en
if passed date ar date so gregorian date string will returns
else umalqura date will returns.

using System.Globalization;

  public static string ServerSideMethod(string date, string lang)
    {
        string result = string.Empty;
        if (date.Length > 0)
        {
            UmAlQuraCalendar umAlQuraCal = new UmAlQuraCalendar();
            CultureInfo umAlQuraCulture = new CultureInfo("ar-SA");
            GregorianCalendar gregCal = new GregorianCalendar();
            CultureInfo gregculture = new CultureInfo("en-US");
            if (lang == "ar")
            {
                DateTime tempDate = DateTime.ParseExact(date, "yyyy-MM-dd", umAlQuraCulture.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
                result = tempDate.ToString("yyyy/MM/dd", gregculture.DateTimeFormat);
            }
            else
            {
                DateTime tempDate = DateTime.ParseExact(date, "yyyy-MM-dd", gregculture.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
                result = tempDate.ToString("yyyy/MM/dd", umAlQuraCulture.DateTimeFormat);
            }
        }
        return result;
    }

No comments:

Post a Comment