MonthDisplayHelper.NumberOfDaysInMonth returns wrong value in MonoDroid

I would like to create Calendar

but it MonthDisplayHelper

returns the wrong value ( 31 for Feb 2013 which is 28 days). What am I doing wrong?

DateTime mRightNow = DateTime.Now;
MonthDisplayHelper mHelper = new MonthDisplayHelper(mRightNow.Year, mRightNow.Month, 2);
Log.Info("cal", mHelper.NumberOfDaysInMonth);

      

+3


source to share


1 answer


You are mixing .Net and Java DateTime classes!

.Net months - 1st level

Java months are 0 based

So DateTime.Now is .Net and returns once in the second month (Feb)

But MonthDisplayHelper is in Java and therefore interprets 2 as 3rd month (March)




Fix it using mRightNow-1

Perhaps consider making this more readable by using an extension method

public static class JavaDateTimeExtensions
{
    public static int JavaMonth(this DateTime input)
    {
        return input.Month - 1;
    }
}

      

+4


source







All Articles