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

可紊 提交于 2020-01-02 07:14:14

问题


I have two text boxes, One in Hijri Date which I am inserting date in this text box using the calender extender. What I want is that upon selection of date (Hijri Date), the Georgian text box will filled with converted Georgian date using C#.

Does anyone has code for changing the hijri date to georgian date?


回答1:


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



来源:https://stackoverflow.com/questions/19751763/convert-from-hijri-to-georgian-date-in-asp-c

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