Convert Calendars

I use these codes to convert the Gregorian calendar to the Julian calendar, and no problem.

private void button1_Click(object sender, EventArgs e) { JulianCalendar juli = new JulianCalendar(); DateTime dt = Convert.ToDateTime(textBox1.Text); int day = juli.GetDayOfMonth(dt); int month = juli.GetMonth(dt); int year = juli.GetYear(dt); string s = string.Format("{0}/{1}/{2}", month, day, year); textBox2.Text = s; } 

This gives me Julian time, but when I want to convert it again to the Gregorian calendar, just at that time, it won't work. I use these following codes to convert the Julian calendar to the Gregorian calendar. what is the problem?

  private void button2_Click(object sender, EventArgs e) { string juli = textBox3.Text; string[] parts = juli.Split('/', '-'); JulianCalendar jul = new JulianCalendar(); DateTime dta = jul.ToDateTime(Convert.ToInt32(parts[0]), Convert.ToInt32(parts[1]), Convert.ToInt32(parts[2]), 0, 0, 0, 0); string sta = dta.ToShortDateString(); textBox4.Text = sta; } 
0
c # winforms
source share
1 answer

the problem is in the order of the parameters. It should be (in the button2_Click event)

 DateTime dta = juli2.ToDateTime(Convert.ToInt32(parts[2]), Convert.ToInt32(parts[0]), Convert.ToInt32(parts[1]), 0, 0, 0, 0); 

since the signature of the ToDateTime method is as follows:

 public virtual System.DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond) 
+1
source share

All Articles