The above code will result in an ArgumentOutOfRangeException saying: Year, Month, and Day parameters describe an un-representable DateTime.
Yes, because unless you specify a calendar, the DateTime
arguments are expected to be Gregorian. You can specify a calendar though:
DateTime d1 = new DateTime(year, month, day, p);
Note that if you now take d1.Year
, you'll get back 2013, not year
... DateTime
is always Gregorian, basically. However, if you use a culture which has the Persian calendar as the default calendar, that will convert the values appropriately when you format a DateTime
into a string. EDIT: Unfortunately, as per the documentation:
Currently, the PersianCalendar class is not an optional calendar for any culture supported by the CultureInfo class and consequently cannot be a default calendar.
As a comment has mentioned Noda Time, I can address that: it doesn't support the Persian calendar yet. It supports the lunar Hijri calendar, but not the solar one :( I could look into adding that into a future release...