0

我使用日期选择器作为所选日期的输入。我想将所选日期转换为其等效的 Shamsi(波斯)日期。我试过这段代码:

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

但它在Convert.ToInt32(Gregorian[1])部分有红色下划线。IDE 说“无法从 'int' 转换为 'system.DateTime'。请帮助我。

4

1 回答 1

1

我试过这个:

       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));
    }
于 2020-12-10T15:10:15.403 回答