Laith Zraikat

I Innovate, Therefore I Am.

Converting a date from Gregorian calendar to Hijri

This piece of code will take the date you give it, and convert it to its equivilant under the Hijri or Gregorian calendar according to your arguments. It will also enable you to set the language in which you wish to display the Gregorian dates (Hijri date will always be displayd in arabic).


C#

public string ConvertDateCalendar(DateTime DateConv, string Calendar, string DateLangCulture)
{
DateTimeFormatInfo DTFormat;
DateLangCulture = DateLangCulture.ToLower();
/// We can't have the hijri date writen in English. We will get a runtime error - LAITH - 11/13/2005 1:01:45 PM -

if (Calendar == "Hijri" && DateLangCulture.StartsWith("en-"))
{
DateLangCulture = "ar-sa";
}

/// Set the date time format to the given culture - LAITH - 11/13/2005 1:04:22 PM -
DTFormat = new System.Globalization.CultureInfo(DateLangCulture, false).DateTimeFormat;

/// Set the calendar property of the date time format to the given calendar - LAITH - 11/13/2005 1:04:52 PM -
switch (Calendar)
{
case"Hijri":
DTFormat.Calendar = new System.Globalization.HijriCalendar();
break;

case"Gregorian":
DTFormat.Calendar = new System.Globalization.GregorianCalendar();
break;

default:
return"";
}

/// We format the date structure to whatever we want - LAITH - 11/13/2005 1:05:39 PM -
DTFormat.ShortDatePattern = "dd/MM/yyyy";
return (DateConv.Date.ToString("f", DTFormat));
}




Add a Comment

Hadeel Barakat from Jordan
August, 03, 2006 12:41 PM
Hi laith how are you? am very interested in you solutions and i wonna ask you if you can help me ?

i need a VB.Net control like datetimepicker but in Arabic so if have any clue please tell me.