简体   繁体   中英

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

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.

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));
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM