As you see in code below The answer of code in last line must be: Persian calendar: 5/30/1383 8:30:15 PM But It is: Persian calendar: 11/11/2625 8:30:15 PM How can I avoid this BUG? // Start Of Code System.Globalization.PersianCalendar jc = new System.Globalization.PersianCalendar(); DateTime thisDate = new DateTime(2004, 8, 20); Console.WriteLine("GetMonth: month = {0}", jc.GetMonth(thisDate)); Console.WriteLine("GetDayOfMonth: month = {0}", jc.GetDayOfMonth(thisDate)); Console.WriteLine("GetYear: year = {0}", jc.GetYear(thisDate)); DateTime dt1 = new DateTime(thisDate.Year, thisDate.Month, thisDate.Day, 20, 30, 15, 500); DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, thisDate.Day, 20, 30, 15, 500, System.Globalization.PersianCalendar.PersianEra); Console.WriteLine("Gregorian calendar: {0}\n" + "Persian calendar: {1}", dt1, dt2); // End Of Code
There is inconsistency in the code: 1 - When you fill the datetime in the following line, you are actually passing Gregorian date instead of Persian dates: [quoted text, click to view] > DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, > thisDate.Day, 20, 30, 15, 500, > System.Globalization.PersianCalendar.PersianEra);
You should pass the Persian dates and not Gregorian date, for example your code should look like this: DateTime dt2 = jc.ToDateTime(jc.GetYear(thisDate), jc.GetMonth(thisDate), jc.GetDayOfMonth(thisDate), 20, 30, 15, 500, System.Globalization.PersianCalendar.PersianEra); All dates, irrespective of the calendar, are stored in the same manner. So if you want to display non-Gregorian date, then you need to specify it. You are simply printing the DateTime and this default to Gregorian. The PersianCalendar is not a full calendar in .NET framework 2.0. So you can't parse dates using it. [quoted text, click to view] "kourosh" wrote: > As you see in code below The answer of code in last line must be: > Persian calendar: 5/30/1383 8:30:15 PM > But It is: > Persian calendar: 11/11/2625 8:30:15 PM > How can I avoid this BUG? > > // Start Of Code > System.Globalization.PersianCalendar jc = new > System.Globalization.PersianCalendar(); > DateTime thisDate = new DateTime(2004, 8, 20); > Console.WriteLine("GetMonth: month = {0}", jc.GetMonth(thisDate)); > Console.WriteLine("GetDayOfMonth: month = {0}", jc.GetDayOfMonth(thisDate)); > Console.WriteLine("GetYear: year = {0}", jc.GetYear(thisDate)); > DateTime dt1 = new DateTime(thisDate.Year, thisDate.Month, thisDate.Day, 20, > 30, 15, 500); > DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, thisDate.Day, > 20, 30, 15, 500, System.Globalization.PersianCalendar.PersianEra); > Console.WriteLine("Gregorian calendar: {0}\n" + "Persian calendar: {1}", > dt1, dt2); > // End Of Code
Dear Dlasheen, I try with syntax that you write, but the result is false, jc.ToDateTime convert persian calendar to Gregorian Calendar for example it convert: 1385/03/11 -> 2006/06/01. How can I show persian calendar using: dt2? [quoted text, click to view] "DLasheen" wrote: > There is inconsistency in the code: > 1 - When you fill the datetime in the following line, you are actually > passing Gregorian date instead of Persian dates: > > DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, > > thisDate.Day, 20, 30, 15, 500, > > System.Globalization.PersianCalendar.PersianEra); > > You should pass the Persian dates and not Gregorian date, for example your > code should look like this: > DateTime dt2 = jc.ToDateTime(jc.GetYear(thisDate), jc.GetMonth(thisDate), > jc.GetDayOfMonth(thisDate), 20, 30, 15, 500, > System.Globalization.PersianCalendar.PersianEra); > > All dates, irrespective of the calendar, are stored in the same manner. So > if you want to display non-Gregorian date, then you need to specify it. > You are simply printing the DateTime and this default to Gregorian. > > The PersianCalendar is not a full calendar in .NET framework 2.0. So you > can't parse dates using it. > > > "kourosh" wrote: > > > As you see in code below The answer of code in last line must be: > > Persian calendar: 5/30/1383 8:30:15 PM > > But It is: > > Persian calendar: 11/11/2625 8:30:15 PM > > How can I avoid this BUG? > > > > // Start Of Code > > System.Globalization.PersianCalendar jc = new > > System.Globalization.PersianCalendar(); > > DateTime thisDate = new DateTime(2004, 8, 20); > > Console.WriteLine("GetMonth: month = {0}", jc.GetMonth(thisDate)); > > Console.WriteLine("GetDayOfMonth: month = {0}", jc.GetDayOfMonth(thisDate)); > > Console.WriteLine("GetYear: year = {0}", jc.GetYear(thisDate)); > > DateTime dt1 = new DateTime(thisDate.Year, thisDate.Month, thisDate.Day, 20, > > 30, 15, 500); > > DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, thisDate.Day, > > 20, 30, 15, 500, System.Globalization.PersianCalendar.PersianEra); > > Console.WriteLine("Gregorian calendar: {0}\n" + "Persian calendar: {1}", > > dt1, dt2); > > // End Of Code
You have to explicitly use dt2 in the persian calendar. For example use the code below to display the date using the format "dd/mm/yy". textBox1.Text = jc.GetDayOfMonth(dt2) + "/" + jc.GetMonth(dt2) + "/" + jc.GetYear(dt2); This should give you the expected output [quoted text, click to view] "kourosh" wrote: > Dear Dlasheen, > I try with syntax that you write, but the result is false, jc.ToDateTime > convert persian calendar to Gregorian Calendar for example it convert: > 1385/03/11 -> 2006/06/01. > How can I show persian calendar using: dt2? > > "DLasheen" wrote: > > > There is inconsistency in the code: > > 1 - When you fill the datetime in the following line, you are actually > > passing Gregorian date instead of Persian dates: > > > DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, > > > thisDate.Day, 20, 30, 15, 500, > > > System.Globalization.PersianCalendar.PersianEra); > > > > You should pass the Persian dates and not Gregorian date, for example your > > code should look like this: > > DateTime dt2 = jc.ToDateTime(jc.GetYear(thisDate), jc.GetMonth(thisDate), > > jc.GetDayOfMonth(thisDate), 20, 30, 15, 500, > > System.Globalization.PersianCalendar.PersianEra); > > > > All dates, irrespective of the calendar, are stored in the same manner. So > > if you want to display non-Gregorian date, then you need to specify it. > > You are simply printing the DateTime and this default to Gregorian. > > > > The PersianCalendar is not a full calendar in .NET framework 2.0. So you > > can't parse dates using it. > > > > > > "kourosh" wrote: > > > > > As you see in code below The answer of code in last line must be: > > > Persian calendar: 5/30/1383 8:30:15 PM > > > But It is: > > > Persian calendar: 11/11/2625 8:30:15 PM > > > How can I avoid this BUG? > > > > > > // Start Of Code > > > System.Globalization.PersianCalendar jc = new > > > System.Globalization.PersianCalendar(); > > > DateTime thisDate = new DateTime(2004, 8, 20); > > > Console.WriteLine("GetMonth: month = {0}", jc.GetMonth(thisDate)); > > > Console.WriteLine("GetDayOfMonth: month = {0}", jc.GetDayOfMonth(thisDate)); > > > Console.WriteLine("GetYear: year = {0}", jc.GetYear(thisDate)); > > > DateTime dt1 = new DateTime(thisDate.Year, thisDate.Month, thisDate.Day, 20, > > > 30, 15, 500); > > > DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, thisDate.Day, > > > 20, 30, 15, 500, System.Globalization.PersianCalendar.PersianEra); > > > Console.WriteLine("Gregorian calendar: {0}\n" + "Persian calendar: {1}", > > > dt1, dt2); > > > // End Of Code
Don't see what you're looking for? Try a search.
|