How to convert Gregorian date (date picker) to Shamsi?

692 views Asked by At

I use a date picker as an input for selected date. I want to convert the selected date into its equivalent Shamsi (persian) date. I tried this code:

private void button2_Click(object sender, EventArgs e)
    {
        string[] Gregorian = Convert.ToString(dateTimePicker1.Value.ToShortDateString()).Split('/');
        PersianCalendar persian = new PersianCalendar();
        label4.Text = string.Format("{0}/{1}/{2}", persian.GetYear(Convert.ToInt32(Gregorian[2]), persian.GetMonth(Convert.ToInt32(Gregorian[0]), persian.GetDayOfMonth(Convert.ToInt32(Gregorian[1])));
    }

But it has red underline in Convert.ToInt32(Gregorian[1]) section. The IDE says "cannot convert from 'int' to 'system.DateTime'. Please help me.

1

There are 1 answers

0
Alex On BEST ANSWER

I tried this:

       private void button2_Click(object sender, EventArgs e)
    {
        
        PersianCalendar persian = new PersianCalendar();
        label4.Text = string.Format("{0}/{1}/{2}", persian.GetYear(dateTimePicker1.Value), persian.GetMonth(dateTimePicker1.Value), persian.GetDayOfMonth(dateTimePicker1.Value));
    }