Convert From Hijri to Georgian date in ASP & C#?

荒凉一梦 提交于 2019-12-05 22:31:38

You can simply convert between Hijri and Gregorian using the built in CultureInfo class

Imports System.Globalization

Private Sub Convert_From_Hijri_To_Gregorian(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim arCI As CultureInfo = New CultureInfo("ar-SA")
    Dim hijri As String = Me.TextBox1.Text   '//check if string is valid date first

    Dim tempDate As DateTime = DateTime.ParseExact(hijri, "dd/MM/yyyy", arCI.DateTimeFormat, DateTimeStyles.AllowInnerWhite)
    Me.TextBox2.Text = tempDate.ToString("dd/MM/yyyy")

End Sub

I am not a C# guy but here is my the conversion of the above code to C#

using System.Globalization;

private void Convert_From_Hijri_To_Gregorian(System.Object sender, System.EventArgs e)
{
    CultureInfo arCI = new CultureInfo("ar-SA");
    string hijri = TextBox1.Text;

    DateTime tempDate = DateTime.ParseExact(hijri, "dd/MM/yyyy", arCI.DateTimeFormat, DateTimeStyles.AllowInnerWhite);
    TextBox2.Text = tempDate.ToString("dd/MM/yyyy");


}

I have written this code after reading this article

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!