Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a Jalali month to a Jalali Date

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?

like image 869
Mahdi Tahsildari Avatar asked Mar 24 '13 10:03

Mahdi Tahsildari


1 Answers

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);
like image 79
Sina Iravanian Avatar answered Nov 20 '22 14:11

Sina Iravanian