تحويل التاريخ من الهجري إلى الميلادي والعكس
C# AND VB.NET
أولا : التحويل من التاريخ الميلادي إلى الهجري
1-فيجوال بيسك
Public Function convertToHijri(greg As String) As String
Dim h As New HijriCalendar()
Dim g As New GregorianCalendar(GregorianCalendarTypes.USEnglish)
Dim tempDate As DateTime = Convert.ToDateTime(greg)
Dim date3 As New DateTime(tempDate.Year, tempDate.Month, tempDate.Day, g)
Dim hijri As String = h.GetYear(date3).ToString() + "/" + h.GetMonth(date3).ToString() + "/" + h.GetDayOfMonth(date3).ToString()
Dim tempDate2 As DateTime = Convert.ToDateTime(hijri)
hijri = tempDate2.ToString("yyyy/MM/dd")
Return hijri
End Function
2-c#
public string convertToHijri(string greg)
{
HijriCalendar h = new HijriCalendar();
GregorianCalendar g = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
DateTime tempDate = Convert.ToDateTime(greg);
DateTime date3 = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, g);
string hijri = h.GetYear(date3).ToString() + "/" + h.GetMonth(date3).ToString() + "/" + h.GetDayOfMonth(date3).ToString();
DateTime tempDate2 = Convert.ToDateTime(hijri);
hijri = tempDate2.ToString("yyyy/MM/dd");
return hijri;
}
ثانياً : التحويل من التاريخ الهجري إلى الميلادي
1-فيجوال بيسك
Public Function convertoAD(hijri As String) As String
Dim h As New HijriCalendar()
Dim g As New GregorianCalendar(GregorianCalendarTypes.USEnglish)
Dim tempDate As DateTime = Convert.ToDateTime(hijri)
Dim date3 As New DateTime(tempDate.Year, tempDate.Month, tempDate.Day, h)
Dim ad As String = g.GetYear(date3).ToString() + "/" + g.GetMonth(date3).ToString() + "/" + g.GetDayOfMonth(date3).ToString()
Dim tempDate2 As DateTime = Convert.ToDateTime(ad)
ad = tempDate2.ToString("yyyy/MM/dd")
Return ad
End Function
2-c#
public string convertoAD(string hijri)
{
HijriCalendar h = new HijriCalendar();
GregorianCalendar g = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
DateTime tempDate = Convert.ToDateTime(hijri);
DateTime date3 = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, h);
string ad = g.GetYear(date3).ToString() + "/" + g.GetMonth(date3).ToString() + "/" + g.GetDayOfMonth(date3).ToString();
DateTime tempDate2 = Convert.ToDateTime(ad);
ad = tempDate2.ToString("yyyy/MM/dd");
return ad;
}
إرسال تعليق