문제

I have a date in Jalali (Persian system of Date) which I need to be forwarded 1 month. The problem is that when I add 1 month using myDateTime.AddMonths(1) my date forwards by 1 Gregorian month, whereas I want a Jalali month.

For example if my Date (Format: yyyy-MM-dd) is 2013-02-28 Gregorian and 1391/12/10 Jalali, and I add one month it will be 2013-03-28 Gregorian (that is alright) and 1392/01/08 (that is wrong and should be 1392/01/10 ).

Having said all the story above, is there a way I can Add one month to a date based on my culture or region or something?

도움이 되었습니까?

해결책

You can use System.Globalization.PersianCalendar instance methods (which pretty much behave like static methods), as in:

var persianCalendar = new System.Globalization.PersianCalendar();
var today = DateTime.Today;
var nextMonth = persianCalendar.AddMonths(today, 1);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top