![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, thisDate.Day, 20, 30, 15, 500, System.Globalization.PersianCalendar.PersianEra); |
|
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 |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |