c# - Is it possible to represent non gregorian dates as DateTime in .NET? -


i'm having trouble representing persian (solar hijri calendar) dates datetime in c#, on days of particular months, example 31/04 in gregorian calendar such date meaningless:

system.globalization.persiancalendar p = new system.globalization.persiancalendar(); datetime date = new datetime(2013,7,22); int year = p.getyear(date); int month = p.getmonth(date); int day = p.getdayofmonth(date); datetime d1 = new datetime(year, month, day); 

the above code result in argumentoutofrangeexception saying: year, month, , day parameters describe un-representable datetime.

which expected.

how can represent persian dates datetimes in .net taking accounts dates such 30/02 , 31/04?

the above code result in argumentoutofrangeexception saying: year, month, , day parameters describe un-representable datetime.

yes, because unless specify calendar, datetime arguments expected gregorian. can specify calendar though:

datetime d1 = new datetime(year, month, day, p); 

note if take d1.year, you'll 2013, not year... datetime always gregorian, basically. however, if use culture has persian calendar default calendar, convert values appropriately when format datetime string. edit: unfortunately, per documentation:

currently, persiancalendar class not optional calendar culture supported cultureinfo class , consequently cannot default calendar.

as comment has mentioned noda time, can address that: doesn't support persian calendar yet. supports lunar hijri calendar, not solar 1 :( adding future release...


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -